如何使用onActivityResult方法,从非活动类等 [英] How to use onActivityResult method from other than Activity class

查看:187
本文介绍了如何使用onActivityResult方法,从非活动类等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个应用程序,我需要找到用户的当前位置。

I am creating an app where i need to find current location of user .

所以在这里我想这样做就像当从系统的意图用户的回报,我的任务应该在那之后完成了各项任务。(显示用户当前的位置)

So here I would like to do a task like when user returns from that System intent, my task should be done after that.(Displaying users current location)

所以我打算使用 OnActivityResult()

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

}

但问题是,我不知道我怎么能在未延伸活动一类使用该方法。

But the problem is that I don't know how can I use that method in a class which is not extending Activity.

请一些人给我的想法我怎么能做到这一点?

Please some one give me idea how can i achieve this?

推荐答案

最后我得到了我所需要的,也为这个问题的解决方案。

Finally i got what i need and also the solution for this question.

 Activity con;
Intent intent_= new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            con.startActivityForResult(intent_, 0);

现在我可以在这里创建一个方法,

Now i can create a method here,

public void startActivityForResult(Intent i, int code)
{
    Log.e("", "insede method startActivityForResult()");
}

通过使用该系统不创建一个子活动为我的意图的话,这种方法得到之后才从意向用户返回调用。

By using this System is not creating a sub-activity for my intent so,this method gets called only after user return from intent.

这篇关于如何使用onActivityResult方法,从非活动类等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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