Android的onActivityResult从来没有所谓的 [英] Android onActivityResult NEVER called

查看:152
本文介绍了Android的onActivityResult从来没有所谓的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的onActivityResult方法不会被调用。是采用Android 2.2

my onActivityResult method is never called. am using android 2.2

我使用的是Tabhost,其中TabHosts都包含有个人活动TabGroups。

I am using a Tabhost, where TabHosts contain TabGroups which contain individual Activities.

我的一个个人活动的运行以下意图

One of my individual activity runs the following intent

 Intent intent = new Intent(); 
 intent.setType("image/*");
 intent.setAction(Intent.ACTION_GET_CONTENT);
 startActivityForResult(Intent.createChooser(intent,
                    "Select Picture"), 0);

这载入我的图片库的应用程序,我用的是默认的Andr​​oid库中选择一个图像,当我回到我的onActivityResult不叫我的活动。

this loads my gallery apps, I use the default android gallery to select one image and when I return my onActivityResult is not called my activity.

它看起来像这样 - 我把一个断点如果(结果code == 0),所以现在,我onActivityResult的逻辑不应该事

It looks like this - and I put a breakpoint at if(resultCode == 0) , so right now, the logic of my onActivityResult should not matter

 public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == 0) {
        if (requestCode == 0) {
            Uri selectedImageUri = data.getData();

            //OI FILE Manager
            filemanagerstring = selectedImageUri.getPath();

            //MEDIA GALLERY
            selectedImagePath = getPath(selectedImageUri);

            //DEBUG PURPOSE - you can delete this if you want
            if(selectedImagePath!=null)
                System.out.println(selectedImagePath);
            else System.out.println("selectedImagePath is null");
            if(filemanagerstring!=null)
                System.out.println(filemanagerstring);
            else System.out.println("filemanagerstring is null");

            //NOW WE HAVE OUR WANTED STRING
            if(selectedImagePath!=null)
                System.out.println("selectedImagePath is the right one for you!");
            else
                System.out.println("filemanagerstring is the right one for you!");
        }
    }
}

生命周期的功能通常被称为无序和间歇性的tabhost / tabgroup内的活动,让我检查,看看有什么生命周期的功能是被称为画廊关闭后,(一旦出现这种情况,因为我选择从Android画廊的图像)

Lifecycle functions are often called out of order and intermittently for Activities within a tabhost/tabgroup, so I checked to see what lifecycle functions ARE being called after the gallery closes (this happens as soon as I select an image from the android gallery)

在只有一个被称为是 onResume()在我TabHost活动。所以,我试图把完全相同的 onActivityResult()方法,在我的TabHost类还有TabActivity类。与在方法的开始的相同位置设置一个断点。

The only one being called is the onResume() in my TabHost activity. So I tried putting the exact same onActivityResult() method in my TabHost class AS WELL AS the TabActivity class. With a breakpoint in the same location at the beginning of method.

无论这些类的调用。

我画一个空白,现在,我怎么能得到从画廊的应用程序的结果在我的应用程序,如果没有一个内置的接收方法,将对此作出回应。

I'm drawing a blank now, how can I get the result from the gallery app in my app if none of the built in receiving methods will respond to it.

因为我知道,我的主要TabHost得到 onResume()叫,我试图加入意图显卡= getIntent(); 来看看它是否会从库中选择接收数据,它没有,所以我不看我怎么可以做的onResume逻辑()方法。

Since I know that my main TabHost gets the onResume() called, I tried added Intent graphics = getIntent(); to see if it would receive data from the gallery selection, it does not, so I don't see how I can do the logic in the onResume() method either.

解决方案欢迎! :)

推荐答案

解决的办法是调用一个透明的活动在主要活动上。这种透​​明的活性是在tabhost前面,将具有正常的生命周期功能。

The solution is to call a transparent activity over top of the main activity. This transparent activity is in front of the tabhost and will have normal lifecycle functions.

这透明的活动调用库意图的onCreate(),它就会一切恢复正常一样在onActivityResult,你将能够通过信息返回到像正常的应用程序的其余部分。完成()是onActivityResult方法的内部,因此用户一个透明的活动被称为从来没有通知。

This transparent activity calls the gallery intent onCreate(), it gets everything returned like normal in its onActivityResult and you will be able to pass the information returned back to the rest of the app like normal. finish() is inside of the onActivityResult method, so the user never even notices that a transparent activity was called.

更新从复制的意见:

活动一经正常的意图调用b活动。活动B没有XML和运行的onCreate这样

Activity A calls Activity B via normal intent. Activity B has no xml and runs onCreate like this

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    //setContentView(R.layout.dialogpopper); 

    Intent intent = new Intent(Intent.ACTION_PICK); 
    intent.setType("image/*"); startActivityForResult(intent, 0);

}//end onCreate 

和活动时,C的完成它调用b活动的onActivityResult

and when Activity C is finished it calls the onActivityResult of Activity B

这篇关于Android的onActivityResult从来没有所谓的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆