Android 在选项卡中的嵌套活动中使用 startActivityForResult。

发布于 2024-11-27 03:27:31 字数 2297 浏览 0 评论 0原文

我正在编写一个应用程序,该应用程序由在选项卡主机中创建的多个选项卡组成,其中:

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 但唯一可能有用的答案是重定向到 如何从 TabHost 活动返回结果 (startActivityForResult)?< /a> 这是一个关于从基本活动中使用 startActivityForResult 来启动 tabActivity 的问题,而不是从 tabActivity 启动活动,所以它没有用。

我还经常看到人们说,当您使用 ActivityGroup 时,这不起作用,但没有人建议还有其他方法可以做到这一点。

任何帮助将不胜感激。

I am writing an application that is composed of several tabs created in a tabhost with:

intent = new Intent().setClass(this, Home.class);
    spec = tabHost.newTabSpec("Home").setIndicator("Home",
                      res.getDrawable(R.drawable.home))
                  .setContent(intent);
    tabHost.addTab(spec);

In the tab in question I am using an ActivityGroup to change to different Activities in the tab:

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);

From one of these Activities I need to take a picture and I am trying to use the default camera app on the device using:

//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);

This starts the camera app correctly, but after taking a picture it does not enter the onActivityResult method. I've tried placing this method in every class in the chain for the tab and it doesn't enter the code in any of them.

I noticed that this question was asked before at How to startactivityforresult in tab child of TabHost but the only potentially useful answer was a redirect to How to return a result (startActivityForResult) from a TabHost Activity? which is a question about using startActivityForResult from a basic Activity to start a tabActivity and not starting an Activity from a tabActivity so it was no use.

I also keep seeing people say that this doesn't work when you're using an ActivityGroup, but no one suggests how else to go about doing it.

Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘逸的'云 2024-12-04 03:27:31

好吧,我找到了解决这个问题的办法。

首先,我创建了另一个活动,我使用基本的 startActivity() 调用开始该活动,我将其称为结果控制器。这不会将任何数据传递回选项卡式活动,这意味着您不必担心它的去向。

其次,我创建了一个简单的静态数据类,我将其称为 DataConnector。 ResultController 将获取 DataConnector 的实例并在那里插入数据

然后,在原始活动(在选项卡中)中,我实现了 onWindowFocusChanged 方法来确定用户何时返回到它。我获得了 DataConnector 的实例,并且能够从那里提取我需要的数据。

Alright, I was able to find a solution to this problem.

First, I created another activity that I started using the basic startActivity() call I called a Result Controller. This does not pass any data back to the tabbed activity which means you don't have to worry about where it's going.

Second, I created a simple static data class which I called DataConnector. The ResultController would get the instance of the DataConnector and insert the Data there

Then, in the original activity(in the tabs) I implemented the onWindowFocusChanged method to determine when the user is back to it. I got the instance of DataConnector and was able to pull the data I needed out of there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文