如何实现Facebook"新故事"功能等功能?

Chi*_*ani 8 android push-notification android-intent android-service

我想在我的应用程序中实现以下功能.

在此输入图像描述

我怎样才能做到这一点?

我有两种方式:

  1. 从获得总岗位数的web服务每1分钟或一段时间后.但为此我需要Thread在后台连续运行一个,否则可能会出现性能问题.(电池性能)

  2. 我可以通过Notification服务执行此功能吗?

或者如果有人有其他想法,请建议我.

Rav*_*avi 5

这样做是个好主意push notification.您可以在推送通知中设置标记并根据需要对其进行过滤.

创建Broadcast在收到notification特定标志时将被调用的内容.

Intent intent = new Intent("newStory");
sendBroadcast(intent);
Run Code Online (Sandbox Code Playgroud)

在那个广播接收方法显示ImageLayout.

private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.e("receiver", "Got message: ");
        //show new story image
    }
};
Run Code Online (Sandbox Code Playgroud)

onResume()注册你的Broadcast.

registerReceiver(mMessageReceiver, new IntentFilter("newStory"));
Run Code Online (Sandbox Code Playgroud)

onPause()注销它.

unregisterReceiver(mMessageReceiver);
Run Code Online (Sandbox Code Playgroud)