Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何实现Facebook之类的功能;“新故事”;特征?_Android_Android Intent_Push Notification_Android Service - Fatal编程技术网

Android 如何实现Facebook之类的功能;“新故事”;特征?

Android 如何实现Facebook之类的功能;“新故事”;特征?,android,android-intent,push-notification,android-service,Android,Android Intent,Push Notification,Android Service,我想在我的应用程序中实现以下功能 我该怎么做? 我有两种想法: 每隔1分钟或一段时间从webservice获取帖子总数。 但为此,我需要在后台连续运行一个线程,因此可能会出现性能问题 我是否可以使用通知服务执行此功能 或者,如果有人有其他想法,请建议我。最好使用推送通知。您可以在推送通知中设置标志,并根据需要对其进行过滤 创建广播,当您收到相关标志的通知时将调用该广播 Intent intent = new Intent("newStory"); sendBroadcast(intent);

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

我该怎么做?

我有两种想法:

  • 每隔1分钟或一段时间从webservice获取帖子总数。 但为此,我需要在后台连续运行一个
    线程
    ,因此可能会出现性能问题

  • 我是否可以使用
    通知
    服务执行此功能


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

    最好使用
    推送通知。您可以在推送通知中设置标志,并根据需要对其进行过滤

    创建
    广播
    ,当您收到相关标志的
    通知
    时将调用该广播

    Intent intent = new Intent("newStory");
    sendBroadcast(intent);
    
    在该广播接收方法上显示
    图像
    布局

    private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.e("receiver", "Got message: ");
            //show new story image
        }
    };
    
    onResume()中
    注册您的
    广播

    registerReceiver(mMessageReceiver, new IntentFilter("newStory"));
    
    onPause()
    中注销它

    unregisterReceiver(mMessageReceiver);
    

    好的,我也这么认为。你们能告诉我这个过程的性能吗。哪一种性能更好?每1分钟后推送通知或调用webservice?