Communication between TabActivity and the embedded activity

后端 未结 5 800
Happy的楠姐
Happy的楠姐 2021-01-14 15:44

I am trying to figure out the best practice of communication between a TabActivity and the child activity embedded in this TabActivity.

In my TabActivity, there is a

5条回答
  •  旧巷少年郎
    2021-01-14 16:46

    The way above with

    ChildActivity childActivity = (ChildActivity) getLocalActivityManager().getActivity("Tab 1");
    childActivity.onNewIntent(intent);
    

    is not very nice. Instead of invoking your activity method directly (it can be null!!!) better do it this way:

    Intent intent = new Intent(this, ChildActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(AlbumBrowser.INTENT_EXTRA_FILTER, mediaTitle);
    getLocalActivityManager().startActivity("activityIdHere", intent);
    

提交回复
热议问题