keeping background service alive after user exit app [duplicate]
According to the Android documentation you can achieve this behavior by using the attribute:
android:isolatedProcess="true"
By the way, I know that it's not answering the question but it might help some people as well - lately, I found out about a great third-party lib that Evernote developers have created. Its name is Android-Job and its aim is to create jobs that run on different processes and can become active again even after a device reboot, it's amazing.
Actually there are different kinds of services you can implement. Use a Service instead of IntentService
. There you need to look at START_STICKY
, START_NOT_STICKY
and START_REDELIVER_INTENT
you can keep your service running in background even if your activity dies. Android services also look at AIDL
services
For this you can use Handler and Runnable class
@Override public void onCreate() { Toast.makeText(context, "SMS SERVICE START", Toast.LENGTH_SHORT).show(); handler=new Handler(); runnable=new Runnable() { @Override public void run() { TASK(); handler.postDelayed(runnable,180000);// 3min delay } }; handler.postDelayed(runnable,180000); super.onCreate(); }
This task run continuously 3min
public void TASK(){ //your task }