I have used the below code to start the service.
Start Service Code:
Intent serviceIntent = new Intent(this, MyService.class);
serviceIntent.putExtra(mConstants.PREF_CHANNEL_NAME, channelName);
startService(serviceIntent);
MyService Code:
@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);
}
When I quit my application the service will be recreated. It will be again calling its onStartCommand Method. Now I want to get the extra data from an intent. But the intent will be null. How to store and restore the intent data in service class.
Please help me on this.