Reputation: 179
I am newbie to Android and creating application to share files. I want to create a service which will check in db that anyone has asked for any files or not for infinite time whether application is on or off. Inshort, I want to create a service same as any normal messanger to check whether any message has come or not. Please suggest me anything in this direction. Any help appreciated.
Upvotes: 1
Views: 304
Reputation: 179
I found my answer. Actually I need to integrate Google FCM push notification in my application. I was unaware about that so that I was thinking about checking same thing in my phone. I was wrong about that. At last I got my answer. Thanks a lot for kind support.
Upvotes: 0
Reputation: 672
Override as shown below onStartCommand in your service class file
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
Next there are chances that your service will be destroyed by android due to low memory for that use Alarmmanager and get alarm callback for every one hour
context.startService(new Intent(context, YourService.class));
public void setAlarm() {
Intent intent = new Intent(context, YourReceiver.class);
PendingIntent alarmIntent = PendingIntent.getBroadcast(context, "1234", intent, PendingIntent.FLAG_UPDATE_CURRENT);
mAlarmMgr.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 3600000 , alarmIntent);
}
Upvotes: 1