Chi*_*ani 8 android push-notification android-intent android-service
我想在我的应用程序中实现以下功能.
我怎样才能做到这一点?
我有两种方式:
从获得总岗位数的web服务每1分钟或一段时间后.但为此我需要Thread在后台连续运行一个,否则可能会出现性能问题.(电池性能)
我可以通过Notification服务执行此功能吗?
或者如果有人有其他想法,请建议我.
这样做是个好主意push notification.您可以在推送通知中设置标记并根据需要对其进行过滤.
创建Broadcast在收到notification特定标志时将被调用的内容.
Intent intent = new Intent("newStory");
sendBroadcast(intent);
Run Code Online (Sandbox Code Playgroud)
在那个广播接收方法显示Image或Layout.
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)
| 归档时间: |
|
| 查看次数: |
696 次 |
| 最近记录: |