Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i start an android service without activity or GUI?

My target Android is 4.1.2. I created an simple android service which will show Toast on boot. But this application should not have any GUI. I was success running this service only from an activity which show GUI on start.

public class MyServices extends Service {
private MediaRecorder recorder = null;
@Override
public IBinder onBind(Intent intent) {

    return null;

}
public int onStartCommand(Intent intent, int flags, int StartId)
{

    Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();

}
}
like image 644
Swadesh Avatar asked Oct 01 '22 13:10

Swadesh


1 Answers

You can start this service from RebootReceiver but As of Android 3.0 the user needs to have started the application at least once before your application can receive android.intent.action.BOOT_COMPLETED events.

Reboot Receiver -> Android BroadcastReceiver on startup - keep running when Activity is in Background

like image 50
Ajay S Avatar answered Oct 05 '22 03:10

Ajay S