本文介绍了异步任务的片段1块另一个异步工作在不同的Fragment2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个活动应用程序采用抽屉菜单

I have single activity App with a drawer menu

public class MainActivity extends ActionBarActivity {
....
void selectItem(int position) {

          Bundle args = new Bundle();
          args.putInt(PageFragment.ARG_Page_NUMBER, position);
          android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
          android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
          android.support.v4.app.Fragment fragment;
          int ActiveFragmentId = 3;
          if(position == 0 ){
             fragment = new Fragment1();
          } else if( position == 1){
        fragment = new Fragment2();
    }
}
....

和两个片段片段1和Fragment2都在他们异步任务

and the two fragments Fragment1 and Fragment2 both have async task in them

现在如果ASNC任务的片段1任务开始(即,坚持onBackground)的片段1异步任务的一个破发点(),如果我切换到Fragment2
在异步任务Fragment2将无法正常工作,直到执行片段1的onPostExceute()。这是为什么?

Now if the Asnc Task in Fragment1 task is started(i.e. hold a break point on onBackground() of the async task in Fragment1 ) and if i switch to Fragment2the Async Task in Fragment2 will not work until the onPostExceute() of Fragment1 is executed. why is that?

此外getActivity()== NULL,里面Fragmnet1的异步任务onPostExecute(),而切换到Fragment2

Also getActivity() == null, inside onPostExecute() of Fragmnet1's Async Task, while switching to Fragment2

推荐答案

尽量让同步到两个异步任务。

Try to make synchronized to the two Asynchronous Tasks.

这篇关于异步任务的片段1块另一个异步工作在不同的Fragment2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-23 15:02