不同活动之间的沟通

问题描述:

目前正在开发类似Facebook的社交应用程序android应用程序。 我想要做的是如何显示,当用户从家庭饲料页面饲料的详细信息,然后从那里到另一个饲料相关的页面,并像那里的帖子。不同活动之间的沟通

例如,让我们考虑:

A -> Feeds page(feed id 1, with image containing two person me and my friend) 
B -> Feeds Details Page(Showing that image) 
C -> My friend's profile 

用户从导航供稿页给我的朋友的个人资料和喜欢的形象出现。当用户再次回到提要页面时,我应该如何渲染。

我尝试通过结果的活动来做到这一点,但这对于多个活动来说效率不高。

一个方法是使用本地lroadcasts

例如在饲料活动:

LocalBroadcastManager.getInstance(getApplicationContext()) 
    .registerReceiver(new BroadcastReceiver() { 
     @Override 
     public void onReceive(Context context, Intent intent) { 
      //update your UI here 
     } 
    }, new IntentFilter("photoLiked")); 

,当照片被喜欢发送广播:

LocalBroadcastManager.getInstance(getApplicationContext()) 
     .sendBroadcast(new Intent("photoLiked")) 
+0

是的,并确保你传递一个'ID'或意向与意图 – bidluo

你可以使用一个像Otto这样的活动巴士。

容易使用,一切都非常松散耦合。

http://square.github.io/otto/