我正在编写一个应用程序,该应用程序由在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方法。我已经尝试将此方法放在选项卡的链中的每个类中,并且它不会在任何类中输入代码。
我注意到在How to startactivityforresult in tab child of TabHost之前已经问过这个问题,但唯一可能有用的答案是重定向到How to return a result (startActivityForResult) from a TabHost Activity?,这是一个关于从基本Activity使用startActivityForResult启动tabActivity而不是启动的问题来自tabActivity的活动,所以没用。
我也经常看到有人说当你使用ActivityGroup时这不起作用,但是没有人建议如何去做。
任何帮助都将不胜感激。
答案 0 :(得分:1)
好吧,我能够找到解决这个问题的方法。
首先,我创建了另一个活动,我开始使用基本的startActivity()调用,我称之为结果控制器。这不会将任何数据传递回选项卡式活动,这意味着您不必担心它的位置。
其次,我创建了一个简单的静态数据类,我称之为DataConnector。 ResultController将获取DataConnector的实例并在那里插入数据
然后,在原始活动(在选项卡中)中,我实现了onWindowFocusChanged方法以确定用户何时返回它。我得到了DataConnector的实例,并且能够从那里获取我需要的数据。