我正在编写一个应用程序,该应用程序由在 tabhost 中创建的多个选项卡组成:
intent = new Intent().setClass(this, Home.class);
spec = tabHost.newTabSpec("Home").setIndicator("Home",
res.getDrawable(R.drawable.home))
.setContent(intent);
tabHost.addTab(spec);
在相关选项卡中,我使用 ActivityGroup 更改选项卡中的不同活动:
Intent intent = new Intent(Info1.this, Enroll2.class);
intent.putExtra("info", Info);
View newView = Group.group.getLocalActivityManager().startActivity("Info1", intent
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
Group.group.replaceView(newView);
在其中一项活动中,我需要拍照,并且我尝试使用设备上的默认相机应用程序:
//define the file-name to save photo taken by Camera activity
String fileName = "picture" + Integer.toString(pictureCount);
//create parameters for Intent with filename
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
values.put(MediaStore.Images.Media.DESCRIPTION,"Image capture by camera");
//imageUri is the current activity attribute, define and save it for later usage (also in onSaveInstanceState)
imageUri = getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
//create new Intent
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
这样可以正确启动相机应用程序,但是拍照后它不会进入 onActivityResult 方法。我尝试将此方法放置在选项卡链中的每个类中,但它不会在其中任何一个类中输入代码。
我注意到这个问题之前被问过如何在 TabHost 的选项卡子项中启动活动以获得结果 https://stackoverflow.com/questions/4529160/how-to-startactivityforresult-in-tab-child-of-tabhost但唯一可能有用的答案是重定向到如何从 TabHost Activity 返回结果 (startActivityForResult)? https://stackoverflow.com/questions/2497205/how-to-return-a-result-startactivityforresult-from-a-tabhost-activity这是一个关于从基本活动中使用 startActivityForResult 来启动 tabActivity 的问题,而不是从 tabActivity 启动活动,所以它没有用。
我还经常看到人们说,当您使用 ActivityGroup 时,这不起作用,但没有人建议还有其他方法可以做到这一点。
任何帮助,将不胜感激。