If you want to make an Android app to always run in background, then below is the process of doing it.
You have to start a service in your Application class to run it
always.
If you do that, your service will be always running. Even though user
terminates your app from task manager or force stop your app, it will
start running again.
Create a service:
Create a service:
Create an Application class and start your service:public class YourService extends Service { @Nullable @Override public IBinder onBind(Intent intent) { return null; } @Override public int onStartCommand(Intent intent, int flags, int startId) { // do your jobs here return super.onStartCommand(intent, flags, startId); } }
Don't forget add this in "application" tag of your AndroidManifest.xmlpublic class App extends Application { @Override public void onCreate() { super.onCreate(); startService(new Intent(this, YourService.class)); } }
android:name=".App"
No comments:
Post a Comment