当活动开始,获取的onActivityResult不叫当其完成 [英] onActivityResult gets called when Activity starts, not when its finished

查看:128
本文介绍了当活动开始,获取的onActivityResult不叫当其完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一些选项卡的FragmentActivity。当我打电话的附加活动(我使用的用户可设置preferences)与startActivityForResult当我开始这个preference活动的onActivityResult被调用的方法(如果它在FragmentActivity或ListFragment无差异),但不当我完成它,因为我希望它(同样没有区别,如果它在FragmentActivity或ListFragment)。之后,我完成preference活动这种方法不会被调用的。

我的问题是,我想我刷新当前选项卡(并设置上次使用的标签ID)后,我完成了preference活动,我希望能够做到这一点的方法的onActivityResult。

这是该类创建preference活动:

 公共抽象类ListFragmentBase< I>扩展ListFragment工具
LoaderCallbacks<名单,LT; I>> {

这是方法我转发到这个类里面的preference活动:

 保护无效forwardTo preferences(INT currentTab){
        意向意图=新意图(getActivity(),全球preferencesActivity.class);
        。getActivity()startActivityForResult(意向,10);
}

这是被调用以上,但不是方法后,我完成了所谓的活动后调用的方法

  @覆盖
公共无效的onActivityResult(INT申请code,INT结果code,意图数据){
    super.onActivityResult(要求code,结果code,数据);
}

这是preference活动:

 公共类全球preferencesActivity延伸活动{

和该类你看我如何调用该方法完成内:

  TextView的confirmSettings =(TextView中)view.findViewById(R.id.confirm_settings);
confirmSettings.setTextSize(preferenceHelper.getSizeHeader(getApplicationContext()));
    confirmSettings.findViewById(R.id.confirm_settings).setOnClickListener(新View.OnClickListener(){
        @覆盖
        公共无效的onClick(查看视图){
            如果(BaseFragmentActivity.lastActivity!= NULL){
                BaseFragmentActivity.lastActivity.onRefreshData();
        }
            组件名callingActivity = getCallingActivity();
            全球preferencesActivity.this.finish();
        }
    });


解决方案

这是Android系统中的错误

<一个href=\"http://stackoverflow.com/questions/3354955/onactivityresult-called-$p$pmaturely\">onActivityResult()所谓prematurely

<一个href=\"http://stackoverflow.com/questions/6966043/why-does-result-from-startactivityforresult-come-before-activity-really-starts\">Why从不会导致startActivityForResult来真正开始活动之前?

我不知道你使用的版本,如果它已经解决/修正

i wrote a FragmentActivity with some tabs. when i call an additional activity (which i use for setting user-preferences) with startActivityForResult (no differences if its in FragmentActivity or in ListFragment) the method onActivityResult gets called when i starts this preference-activity, but not when i finish it, as i would expect it (again no differences if its in FragmentActivity or in ListFragment). after i finish the preference-activity this method does not get called at all.

my problem is that i want to refresh my current tab (and set the last used tab id) after i finished the preference activity and i hoped to be able to do this in the onActivityResult method.

this is the class creating the preference-activity:

public abstract class ListFragmentBase<I> extends ListFragment implements
LoaderCallbacks<List<I>> {

this is the method forwarding me to the preference activity inside this class:

protected void forwardToPreferences(int currentTab){            
        Intent intent = new Intent(getActivity(), GlobalPreferencesActivity.class);
        getActivity().startActivityForResult(intent, 10);
}

this is the method that gets called after calling the method above but not after i finished the called activity

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
}

this is the preference-activity:

public class GlobalPreferencesActivity extends Activity {

and inside that class you see how i call the finish method:

TextView confirmSettings = (TextView) view.findViewById(R.id.confirm_settings);
confirmSettings.setTextSize(PreferenceHelper.getSizeHeader(getApplicationContext()));
    confirmSettings.findViewById(R.id.confirm_settings).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {    
            if(BaseFragmentActivity.lastActivity != null){
                BaseFragmentActivity.lastActivity.onRefreshData();
        }
            ComponentName callingActivity = getCallingActivity();
            GlobalPreferencesActivity.this.finish();
        }
    });

解决方案

It is a bug of Android

onActivityResult() called prematurely

and

Why does result from startActivityForResult come before activity really starts?

I don't know which version you use and if it has been solved/corrected

这篇关于当活动开始,获取的onActivityResult不叫当其完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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