I'm developing an app that have to be always running and be only closable with a task killer or similar.
I have in the manifest:
android:persistent="true"
Although is not closing when pressing home button, I find it closed from time to time and I don't want this to happen.
I user want, can close app by killing it from a custom launcher or using task killer.
Any suggestions? thanks in advance
P.D.: how can you exit the app with the back button, but not closing it, I mean stop showing the app or any of its activities but the app should continue running in background.
I wrote a service but something is not working fine I added this in the manifest
<service android:name=".ONService"></service>
right before the end of application tag, and this is the ONService.java:
package com.omninotifier.main;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
public class ONService extends Service{
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
//super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
//return super.onStartCommand(intent, flags, startId);
return START_STICKY;
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
NotificationManager manager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_stat_alert,
getResources().getString(R.string.ServiceDestroyed), System.currentTimeMillis());
notification.flags = Notification.FLAG_AUTO_CANCEL;
manager.notify(150, notification);
super.onDestroy();
}
}
and I start the service doing this right the app starts:
this is the main activity in the app
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent serviceIntent = new Intent();
serviceIntent.setAction(".ONService");
startService(serviceIntent);
//............
}
I should add intent-filter with actions in the service tag for this to work? or it is other issue?
The problem was that it was unable to start the service. This is the fix:
in Manifest
<service android:name=".ONService">
<intent-filter android:priority="100">
<action android:name=".ONService"/>
</intent-filter>
</service>
in the activity that calls the service:
Intent serviceIntent = new Intent(".ONService");
startService(serviceIntent);