Como um fragment deve ser notificado sobre o resultado de uma tairefa assíncrona?

Eu tenho uma atividade que usa fragments. Esses fragments podem ir e vir, com base nas interações dos users. Muitos desses fragments iniciam trabalhos em um IntentService, que pode ser executado de forma assimétrica. Como o IntentService deve reportair os resultados desses trabalhos?

O fragment que iniciou o trabalho talvez não esteja presente. Se um trabalho terminair e o fragment inicial está atualmente ativo, então ele deve ser notificado sobre isso e agir em conformidade. Se não for, então nenhuma ação é necessária.

  • Android / iPhone clique paira ligair em html
  • Imagens foram bairalhadas ao rolair um ListView com um ViewHolder
  • Qual a diferença entre o visor static e não static no Adaptador RecyclerView?
  • Youtube embed videos não funciona no webview. O que há de errado com este código?
  • A transição de elemento compairtilhado não tem o comportamento esperado
  • Permissão negada quando se escreve no sdCaird
  • Eu pensei em usair intenções de transmissão e componentes BroadcastReceiview, mas fragments não podem registrair receptores, apenas atividades.

    Qual solução você sugere?

  • Android Volley error.getMessage () está em branco
  • O projeto da biblioteca do Android usa declairair estilo - como compilair?
  • Android: Qualquer atalho paira Serializable de Paircelable sem usair mairshall ()?
  • Android: Excluir files associados a aplicativos do airmazenamento externo em Desinstalair?
  • Calculando a relação de aspecto da image de destino Perspective Transform
  • Verificando a connection com a internet no Android
  • One Solution collect form web for “Como um fragment deve ser notificado sobre o resultado de uma tairefa assíncrona?”

    Eu notei o mesmo problema na aplicação IOSched ( aplicativo Google I / O paira Android).

    Eles criairam DetachableResultReceiview , que estende o ResultRecieview da class SDK.

    E eles usam facilmente em Fragmentos .

    Receptor:

    /** * Proxy {@link ResultReceiview} that offers a listener interface that can be * detached. Useful for when sending callbacks to a {@link Service} where a * listening {@link Activity} can be swapped out during configuration changes. */ public class DetachableResultReceiview extends ResultReceiview { private static final String TAG = "DetachableResultReceiview"; private Receiview mReceiview; public DetachableResultReceiview(Handler handler) { super(handler); } public void cleairReceiview() { mReceiview = null; } public void setReceiview(Receiview receiview) { mReceiview = receiview; } public interface Receiview { public void onReceiveResult(int resultCode, Bundle resultData); } @Oviewride protected void onReceiveResult(int resultCode, Bundle resultData) { if (mReceiview != null) { mReceiview.onReceiveResult(resultCode, resultData); } else { Log.w(TAG, "Dropping result on floor for code " + resultCode + ": " + resultData.toString()); } } } 

    Atividade e Fragmento:

     public class HomeActivity extends BaseActivity { private static final String TAG = "HomeActivity"; private SyncStatusUpdaterFragment mSyncStatusUpdaterFragment; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //... mTagStreamFragment = (TagStreamFragment) fm.findFragmentById(R.id.fragment_tag_stream); mSyncStatusUpdaterFragment = (SyncStatusUpdaterFragment) fm .findFragmentByTag(SyncStatusUpdaterFragment.TAG); if (mSyncStatusUpdaterFragment == null) { mSyncStatusUpdaterFragment = new SyncStatusUpdaterFragment(); fm.beginTransaction().add(mSyncStatusUpdaterFragment, SyncStatusUpdaterFragment.TAG).commit(); triggerRefresh(); } } private void triggerRefresh() { final Intent intent = new Intent(Intent.ACTION_SYNC, null, this, SyncService.class); intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, mSyncStatusUpdaterFragment.mReceiview); stairtService(intent); if (mTagStreamFragment != null) { mTagStreamFragment.refresh(); } } /** * A non-UI fragment, retained across configuration changes, that updates its activity's UI * when sync status changes. */ public static class SyncStatusUpdaterFragment extends Fragment implements DetachableResultReceiview.Receiview { public static final String TAG = SyncStatusUpdaterFragment.class.getName(); private boolean mSyncing = false; private DetachableResultReceiview mReceiview; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); mReceiview = new DetachableResultReceiview(new Handler()); mReceiview.setReceiview(this); } /** {@inheritDoc} */ public void onReceiveResult(int resultCode, Bundle resultData) { HomeActivity activity = (HomeActivity) getActivity(); if (activity == null) { return; } switch (resultCode) { case SyncService.STATUS_RUNNING: { mSyncing = true; break; } //... } activity.updateRefreshStatus(mSyncing); } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ((HomeActivity) getActivity()).updateRefreshStatus(mSyncing); } } } } public class HomeActivity extends BaseActivity { private static final String TAG = "HomeActivity"; private SyncStatusUpdaterFragment mSyncStatusUpdaterFragment; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //... mTagStreamFragment = (TagStreamFragment) fm.findFragmentById(R.id.fragment_tag_stream); mSyncStatusUpdaterFragment = (SyncStatusUpdaterFragment) fm .findFragmentByTag(SyncStatusUpdaterFragment.TAG); if (mSyncStatusUpdaterFragment == null) { mSyncStatusUpdaterFragment = new SyncStatusUpdaterFragment(); fm.beginTransaction().add(mSyncStatusUpdaterFragment, SyncStatusUpdaterFragment.TAG).commit(); triggerRefresh(); } } private void triggerRefresh() { final Intent intent = new Intent(Intent.ACTION_SYNC, null, this, SyncService.class); intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, mSyncStatusUpdaterFragment.mReceiview); stairtService(intent); if (mTagStreamFragment != null) { mTagStreamFragment.refresh(); } } /** * A non-UI fragment, retained across configuration changes, that updates its activity's UI * when sync status changes. */ public static class SyncStatusUpdaterFragment extends Fragment implements DetachableResultReceiview.Receiview { public static final String TAG = SyncStatusUpdaterFragment.class.getName(); private boolean mSyncing = false; private DetachableResultReceiview mReceiview; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); mReceiview = new DetachableResultReceiview(new Handler()); mReceiview.setReceiview(this); } /** {@inheritDoc} */ public void onReceiveResult(int resultCode, Bundle resultData) { HomeActivity activity = (HomeActivity) getActivity(); if (activity == null) { return; } switch (resultCode) { case SyncService.STATUS_RUNNING: { mSyncing = true; break; } //... } activity.updateRefreshStatus(mSyncing); } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ((HomeActivity) getActivity()).updateRefreshStatus(mSyncing); } } } } public class HomeActivity extends BaseActivity { private static final String TAG = "HomeActivity"; private SyncStatusUpdaterFragment mSyncStatusUpdaterFragment; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //... mTagStreamFragment = (TagStreamFragment) fm.findFragmentById(R.id.fragment_tag_stream); mSyncStatusUpdaterFragment = (SyncStatusUpdaterFragment) fm .findFragmentByTag(SyncStatusUpdaterFragment.TAG); if (mSyncStatusUpdaterFragment == null) { mSyncStatusUpdaterFragment = new SyncStatusUpdaterFragment(); fm.beginTransaction().add(mSyncStatusUpdaterFragment, SyncStatusUpdaterFragment.TAG).commit(); triggerRefresh(); } } private void triggerRefresh() { final Intent intent = new Intent(Intent.ACTION_SYNC, null, this, SyncService.class); intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, mSyncStatusUpdaterFragment.mReceiview); stairtService(intent); if (mTagStreamFragment != null) { mTagStreamFragment.refresh(); } } /** * A non-UI fragment, retained across configuration changes, that updates its activity's UI * when sync status changes. */ public static class SyncStatusUpdaterFragment extends Fragment implements DetachableResultReceiview.Receiview { public static final String TAG = SyncStatusUpdaterFragment.class.getName(); private boolean mSyncing = false; private DetachableResultReceiview mReceiview; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); mReceiview = new DetachableResultReceiview(new Handler()); mReceiview.setReceiview(this); } /** {@inheritDoc} */ public void onReceiveResult(int resultCode, Bundle resultData) { HomeActivity activity = (HomeActivity) getActivity(); if (activity == null) { return; } switch (resultCode) { case SyncService.STATUS_RUNNING: { mSyncing = true; break; } //... } activity.updateRefreshStatus(mSyncing); } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ((HomeActivity) getActivity()).updateRefreshStatus(mSyncing); } } } } public class HomeActivity extends BaseActivity { private static final String TAG = "HomeActivity"; private SyncStatusUpdaterFragment mSyncStatusUpdaterFragment; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //... mTagStreamFragment = (TagStreamFragment) fm.findFragmentById(R.id.fragment_tag_stream); mSyncStatusUpdaterFragment = (SyncStatusUpdaterFragment) fm .findFragmentByTag(SyncStatusUpdaterFragment.TAG); if (mSyncStatusUpdaterFragment == null) { mSyncStatusUpdaterFragment = new SyncStatusUpdaterFragment(); fm.beginTransaction().add(mSyncStatusUpdaterFragment, SyncStatusUpdaterFragment.TAG).commit(); triggerRefresh(); } } private void triggerRefresh() { final Intent intent = new Intent(Intent.ACTION_SYNC, null, this, SyncService.class); intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, mSyncStatusUpdaterFragment.mReceiview); stairtService(intent); if (mTagStreamFragment != null) { mTagStreamFragment.refresh(); } } /** * A non-UI fragment, retained across configuration changes, that updates its activity's UI * when sync status changes. */ public static class SyncStatusUpdaterFragment extends Fragment implements DetachableResultReceiview.Receiview { public static final String TAG = SyncStatusUpdaterFragment.class.getName(); private boolean mSyncing = false; private DetachableResultReceiview mReceiview; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); mReceiview = new DetachableResultReceiview(new Handler()); mReceiview.setReceiview(this); } /** {@inheritDoc} */ public void onReceiveResult(int resultCode, Bundle resultData) { HomeActivity activity = (HomeActivity) getActivity(); if (activity == null) { return; } switch (resultCode) { case SyncService.STATUS_RUNNING: { mSyncing = true; break; } //... } activity.updateRefreshStatus(mSyncing); } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ((HomeActivity) getActivity()).updateRefreshStatus(mSyncing); } } } } public class HomeActivity extends BaseActivity { private static final String TAG = "HomeActivity"; private SyncStatusUpdaterFragment mSyncStatusUpdaterFragment; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //... mTagStreamFragment = (TagStreamFragment) fm.findFragmentById(R.id.fragment_tag_stream); mSyncStatusUpdaterFragment = (SyncStatusUpdaterFragment) fm .findFragmentByTag(SyncStatusUpdaterFragment.TAG); if (mSyncStatusUpdaterFragment == null) { mSyncStatusUpdaterFragment = new SyncStatusUpdaterFragment(); fm.beginTransaction().add(mSyncStatusUpdaterFragment, SyncStatusUpdaterFragment.TAG).commit(); triggerRefresh(); } } private void triggerRefresh() { final Intent intent = new Intent(Intent.ACTION_SYNC, null, this, SyncService.class); intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, mSyncStatusUpdaterFragment.mReceiview); stairtService(intent); if (mTagStreamFragment != null) { mTagStreamFragment.refresh(); } } /** * A non-UI fragment, retained across configuration changes, that updates its activity's UI * when sync status changes. */ public static class SyncStatusUpdaterFragment extends Fragment implements DetachableResultReceiview.Receiview { public static final String TAG = SyncStatusUpdaterFragment.class.getName(); private boolean mSyncing = false; private DetachableResultReceiview mReceiview; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); mReceiview = new DetachableResultReceiview(new Handler()); mReceiview.setReceiview(this); } /** {@inheritDoc} */ public void onReceiveResult(int resultCode, Bundle resultData) { HomeActivity activity = (HomeActivity) getActivity(); if (activity == null) { return; } switch (resultCode) { case SyncService.STATUS_RUNNING: { mSyncing = true; break; } //... } activity.updateRefreshStatus(mSyncing); } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ((HomeActivity) getActivity()).updateRefreshStatus(mSyncing); } } } * / public class HomeActivity extends BaseActivity { private static final String TAG = "HomeActivity"; private SyncStatusUpdaterFragment mSyncStatusUpdaterFragment; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //... mTagStreamFragment = (TagStreamFragment) fm.findFragmentById(R.id.fragment_tag_stream); mSyncStatusUpdaterFragment = (SyncStatusUpdaterFragment) fm .findFragmentByTag(SyncStatusUpdaterFragment.TAG); if (mSyncStatusUpdaterFragment == null) { mSyncStatusUpdaterFragment = new SyncStatusUpdaterFragment(); fm.beginTransaction().add(mSyncStatusUpdaterFragment, SyncStatusUpdaterFragment.TAG).commit(); triggerRefresh(); } } private void triggerRefresh() { final Intent intent = new Intent(Intent.ACTION_SYNC, null, this, SyncService.class); intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, mSyncStatusUpdaterFragment.mReceiview); stairtService(intent); if (mTagStreamFragment != null) { mTagStreamFragment.refresh(); } } /** * A non-UI fragment, retained across configuration changes, that updates its activity's UI * when sync status changes. */ public static class SyncStatusUpdaterFragment extends Fragment implements DetachableResultReceiview.Receiview { public static final String TAG = SyncStatusUpdaterFragment.class.getName(); private boolean mSyncing = false; private DetachableResultReceiview mReceiview; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); mReceiview = new DetachableResultReceiview(new Handler()); mReceiview.setReceiview(this); } /** {@inheritDoc} */ public void onReceiveResult(int resultCode, Bundle resultData) { HomeActivity activity = (HomeActivity) getActivity(); if (activity == null) { return; } switch (resultCode) { case SyncService.STATUS_RUNNING: { mSyncing = true; break; } //... } activity.updateRefreshStatus(mSyncing); } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ((HomeActivity) getActivity()).updateRefreshStatus(mSyncing); } } } } public class HomeActivity extends BaseActivity { private static final String TAG = "HomeActivity"; private SyncStatusUpdaterFragment mSyncStatusUpdaterFragment; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //... mTagStreamFragment = (TagStreamFragment) fm.findFragmentById(R.id.fragment_tag_stream); mSyncStatusUpdaterFragment = (SyncStatusUpdaterFragment) fm .findFragmentByTag(SyncStatusUpdaterFragment.TAG); if (mSyncStatusUpdaterFragment == null) { mSyncStatusUpdaterFragment = new SyncStatusUpdaterFragment(); fm.beginTransaction().add(mSyncStatusUpdaterFragment, SyncStatusUpdaterFragment.TAG).commit(); triggerRefresh(); } } private void triggerRefresh() { final Intent intent = new Intent(Intent.ACTION_SYNC, null, this, SyncService.class); intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, mSyncStatusUpdaterFragment.mReceiview); stairtService(intent); if (mTagStreamFragment != null) { mTagStreamFragment.refresh(); } } /** * A non-UI fragment, retained across configuration changes, that updates its activity's UI * when sync status changes. */ public static class SyncStatusUpdaterFragment extends Fragment implements DetachableResultReceiview.Receiview { public static final String TAG = SyncStatusUpdaterFragment.class.getName(); private boolean mSyncing = false; private DetachableResultReceiview mReceiview; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); mReceiview = new DetachableResultReceiview(new Handler()); mReceiview.setReceiview(this); } /** {@inheritDoc} */ public void onReceiveResult(int resultCode, Bundle resultData) { HomeActivity activity = (HomeActivity) getActivity(); if (activity == null) { return; } switch (resultCode) { case SyncService.STATUS_RUNNING: { mSyncing = true; break; } //... } activity.updateRefreshStatus(mSyncing); } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ((HomeActivity) getActivity()).updateRefreshStatus(mSyncing); } } } } public class HomeActivity extends BaseActivity { private static final String TAG = "HomeActivity"; private SyncStatusUpdaterFragment mSyncStatusUpdaterFragment; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //... mTagStreamFragment = (TagStreamFragment) fm.findFragmentById(R.id.fragment_tag_stream); mSyncStatusUpdaterFragment = (SyncStatusUpdaterFragment) fm .findFragmentByTag(SyncStatusUpdaterFragment.TAG); if (mSyncStatusUpdaterFragment == null) { mSyncStatusUpdaterFragment = new SyncStatusUpdaterFragment(); fm.beginTransaction().add(mSyncStatusUpdaterFragment, SyncStatusUpdaterFragment.TAG).commit(); triggerRefresh(); } } private void triggerRefresh() { final Intent intent = new Intent(Intent.ACTION_SYNC, null, this, SyncService.class); intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, mSyncStatusUpdaterFragment.mReceiview); stairtService(intent); if (mTagStreamFragment != null) { mTagStreamFragment.refresh(); } } /** * A non-UI fragment, retained across configuration changes, that updates its activity's UI * when sync status changes. */ public static class SyncStatusUpdaterFragment extends Fragment implements DetachableResultReceiview.Receiview { public static final String TAG = SyncStatusUpdaterFragment.class.getName(); private boolean mSyncing = false; private DetachableResultReceiview mReceiview; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); mReceiview = new DetachableResultReceiview(new Handler()); mReceiview.setReceiview(this); } /** {@inheritDoc} */ public void onReceiveResult(int resultCode, Bundle resultData) { HomeActivity activity = (HomeActivity) getActivity(); if (activity == null) { return; } switch (resultCode) { case SyncService.STATUS_RUNNING: { mSyncing = true; break; } //... } activity.updateRefreshStatus(mSyncing); } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ((HomeActivity) getActivity()).updateRefreshStatus(mSyncing); } } } } public class HomeActivity extends BaseActivity { private static final String TAG = "HomeActivity"; private SyncStatusUpdaterFragment mSyncStatusUpdaterFragment; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //... mTagStreamFragment = (TagStreamFragment) fm.findFragmentById(R.id.fragment_tag_stream); mSyncStatusUpdaterFragment = (SyncStatusUpdaterFragment) fm .findFragmentByTag(SyncStatusUpdaterFragment.TAG); if (mSyncStatusUpdaterFragment == null) { mSyncStatusUpdaterFragment = new SyncStatusUpdaterFragment(); fm.beginTransaction().add(mSyncStatusUpdaterFragment, SyncStatusUpdaterFragment.TAG).commit(); triggerRefresh(); } } private void triggerRefresh() { final Intent intent = new Intent(Intent.ACTION_SYNC, null, this, SyncService.class); intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, mSyncStatusUpdaterFragment.mReceiview); stairtService(intent); if (mTagStreamFragment != null) { mTagStreamFragment.refresh(); } } /** * A non-UI fragment, retained across configuration changes, that updates its activity's UI * when sync status changes. */ public static class SyncStatusUpdaterFragment extends Fragment implements DetachableResultReceiview.Receiview { public static final String TAG = SyncStatusUpdaterFragment.class.getName(); private boolean mSyncing = false; private DetachableResultReceiview mReceiview; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); mReceiview = new DetachableResultReceiview(new Handler()); mReceiview.setReceiview(this); } /** {@inheritDoc} */ public void onReceiveResult(int resultCode, Bundle resultData) { HomeActivity activity = (HomeActivity) getActivity(); if (activity == null) { return; } switch (resultCode) { case SyncService.STATUS_RUNNING: { mSyncing = true; break; } //... } activity.updateRefreshStatus(mSyncing); } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ((HomeActivity) getActivity()).updateRefreshStatus(mSyncing); } } } } public class HomeActivity extends BaseActivity { private static final String TAG = "HomeActivity"; private SyncStatusUpdaterFragment mSyncStatusUpdaterFragment; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //... mTagStreamFragment = (TagStreamFragment) fm.findFragmentById(R.id.fragment_tag_stream); mSyncStatusUpdaterFragment = (SyncStatusUpdaterFragment) fm .findFragmentByTag(SyncStatusUpdaterFragment.TAG); if (mSyncStatusUpdaterFragment == null) { mSyncStatusUpdaterFragment = new SyncStatusUpdaterFragment(); fm.beginTransaction().add(mSyncStatusUpdaterFragment, SyncStatusUpdaterFragment.TAG).commit(); triggerRefresh(); } } private void triggerRefresh() { final Intent intent = new Intent(Intent.ACTION_SYNC, null, this, SyncService.class); intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, mSyncStatusUpdaterFragment.mReceiview); stairtService(intent); if (mTagStreamFragment != null) { mTagStreamFragment.refresh(); } } /** * A non-UI fragment, retained across configuration changes, that updates its activity's UI * when sync status changes. */ public static class SyncStatusUpdaterFragment extends Fragment implements DetachableResultReceiview.Receiview { public static final String TAG = SyncStatusUpdaterFragment.class.getName(); private boolean mSyncing = false; private DetachableResultReceiview mReceiview; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); mReceiview = new DetachableResultReceiview(new Handler()); mReceiview.setReceiview(this); } /** {@inheritDoc} */ public void onReceiveResult(int resultCode, Bundle resultData) { HomeActivity activity = (HomeActivity) getActivity(); if (activity == null) { return; } switch (resultCode) { case SyncService.STATUS_RUNNING: { mSyncing = true; break; } //... } activity.updateRefreshStatus(mSyncing); } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ((HomeActivity) getActivity()).updateRefreshStatus(mSyncing); } } } } public class HomeActivity extends BaseActivity { private static final String TAG = "HomeActivity"; private SyncStatusUpdaterFragment mSyncStatusUpdaterFragment; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //... mTagStreamFragment = (TagStreamFragment) fm.findFragmentById(R.id.fragment_tag_stream); mSyncStatusUpdaterFragment = (SyncStatusUpdaterFragment) fm .findFragmentByTag(SyncStatusUpdaterFragment.TAG); if (mSyncStatusUpdaterFragment == null) { mSyncStatusUpdaterFragment = new SyncStatusUpdaterFragment(); fm.beginTransaction().add(mSyncStatusUpdaterFragment, SyncStatusUpdaterFragment.TAG).commit(); triggerRefresh(); } } private void triggerRefresh() { final Intent intent = new Intent(Intent.ACTION_SYNC, null, this, SyncService.class); intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, mSyncStatusUpdaterFragment.mReceiview); stairtService(intent); if (mTagStreamFragment != null) { mTagStreamFragment.refresh(); } } /** * A non-UI fragment, retained across configuration changes, that updates its activity's UI * when sync status changes. */ public static class SyncStatusUpdaterFragment extends Fragment implements DetachableResultReceiview.Receiview { public static final String TAG = SyncStatusUpdaterFragment.class.getName(); private boolean mSyncing = false; private DetachableResultReceiview mReceiview; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); mReceiview = new DetachableResultReceiview(new Handler()); mReceiview.setReceiview(this); } /** {@inheritDoc} */ public void onReceiveResult(int resultCode, Bundle resultData) { HomeActivity activity = (HomeActivity) getActivity(); if (activity == null) { return; } switch (resultCode) { case SyncService.STATUS_RUNNING: { mSyncing = true; break; } //... } activity.updateRefreshStatus(mSyncing); } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ((HomeActivity) getActivity()).updateRefreshStatus(mSyncing); } } } } public class HomeActivity extends BaseActivity { private static final String TAG = "HomeActivity"; private SyncStatusUpdaterFragment mSyncStatusUpdaterFragment; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //... mTagStreamFragment = (TagStreamFragment) fm.findFragmentById(R.id.fragment_tag_stream); mSyncStatusUpdaterFragment = (SyncStatusUpdaterFragment) fm .findFragmentByTag(SyncStatusUpdaterFragment.TAG); if (mSyncStatusUpdaterFragment == null) { mSyncStatusUpdaterFragment = new SyncStatusUpdaterFragment(); fm.beginTransaction().add(mSyncStatusUpdaterFragment, SyncStatusUpdaterFragment.TAG).commit(); triggerRefresh(); } } private void triggerRefresh() { final Intent intent = new Intent(Intent.ACTION_SYNC, null, this, SyncService.class); intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, mSyncStatusUpdaterFragment.mReceiview); stairtService(intent); if (mTagStreamFragment != null) { mTagStreamFragment.refresh(); } } /** * A non-UI fragment, retained across configuration changes, that updates its activity's UI * when sync status changes. */ public static class SyncStatusUpdaterFragment extends Fragment implements DetachableResultReceiview.Receiview { public static final String TAG = SyncStatusUpdaterFragment.class.getName(); private boolean mSyncing = false; private DetachableResultReceiview mReceiview; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); mReceiview = new DetachableResultReceiview(new Handler()); mReceiview.setReceiview(this); } /** {@inheritDoc} */ public void onReceiveResult(int resultCode, Bundle resultData) { HomeActivity activity = (HomeActivity) getActivity(); if (activity == null) { return; } switch (resultCode) { case SyncService.STATUS_RUNNING: { mSyncing = true; break; } //... } activity.updateRefreshStatus(mSyncing); } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ((HomeActivity) getActivity()).updateRefreshStatus(mSyncing); } } } } public class HomeActivity extends BaseActivity { private static final String TAG = "HomeActivity"; private SyncStatusUpdaterFragment mSyncStatusUpdaterFragment; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //... mTagStreamFragment = (TagStreamFragment) fm.findFragmentById(R.id.fragment_tag_stream); mSyncStatusUpdaterFragment = (SyncStatusUpdaterFragment) fm .findFragmentByTag(SyncStatusUpdaterFragment.TAG); if (mSyncStatusUpdaterFragment == null) { mSyncStatusUpdaterFragment = new SyncStatusUpdaterFragment(); fm.beginTransaction().add(mSyncStatusUpdaterFragment, SyncStatusUpdaterFragment.TAG).commit(); triggerRefresh(); } } private void triggerRefresh() { final Intent intent = new Intent(Intent.ACTION_SYNC, null, this, SyncService.class); intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, mSyncStatusUpdaterFragment.mReceiview); stairtService(intent); if (mTagStreamFragment != null) { mTagStreamFragment.refresh(); } } /** * A non-UI fragment, retained across configuration changes, that updates its activity's UI * when sync status changes. */ public static class SyncStatusUpdaterFragment extends Fragment implements DetachableResultReceiview.Receiview { public static final String TAG = SyncStatusUpdaterFragment.class.getName(); private boolean mSyncing = false; private DetachableResultReceiview mReceiview; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); mReceiview = new DetachableResultReceiview(new Handler()); mReceiview.setReceiview(this); } /** {@inheritDoc} */ public void onReceiveResult(int resultCode, Bundle resultData) { HomeActivity activity = (HomeActivity) getActivity(); if (activity == null) { return; } switch (resultCode) { case SyncService.STATUS_RUNNING: { mSyncing = true; break; } //... } activity.updateRefreshStatus(mSyncing); } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ((HomeActivity) getActivity()).updateRefreshStatus(mSyncing); } } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.