
[英]Android GCM Intent Service - How to get Application class
[英]How to restore the intent data of android service class?
我已使用以下代码启动该服务。
启动服务代码:
Intent serviceIntent = new Intent(this, MyService.class);
serviceIntent.putExtra(mConstants.PREF_CHANNEL_NAME, channelName);
startService(serviceIntent);
我的服务代码:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent != null) {
// Get the channel name from the string extras
String channelName = intent
.getStringExtra(mConstants.PREF_CHANNEL_NAME);
} else {
mAppUtilInstance.showToastMessage(mContext,
"No channel name found.");
}
return super.onStartCommand(intent, flags, startId);
}
当我退出应用程序时,将重新创建服务。 它将再次调用其onStartCommand方法。 现在,我想从意图中获取额外的数据。 但是意图将为空。 如何在服务类中存储和还原意图数据。
请帮我。
在onStartCommand中使用它
String data=(String) intent.getExtras().get("data");
编辑:
至于找回意图, START_REDELIVER_INTENT有一个标志,它将重新传递意图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.