0

I created an application that contain a Service that start from button click of Activity.

But I want to create a new application that doing the same as the last one - but don't have any GUI interface => that mean without any Activity.

I want to make the application to start on device boot and never stop (until the device is shutdown) .

How to do it ? Is there any way ?

Yanshof
  • 9,659
  • 21
  • 95
  • 195
  • 1
    Hi, Yanshof! Sorry for disturbing! Do you mind reopening the [4-years-old question](https://stackoverflow.com/q/20869067/3290339). There are few alternative answers the question is lacking of. Those answers are worth to be relieved and might be especially helpful for AOSP starters. Thanks in advance! – Onik Sep 14 '18 at 20:45

1 Answers1

2

How to do it ?

By using Context.startService() or Context.bindService() methods.

where Context might be Activity, Application, argument of the onReceive() method of BroadcastReceiver etc.

Onik
  • 19,396
  • 14
  • 68
  • 91
  • i don't understand - can you please explain – Yanshof Mar 12 '16 at 14:49
  • 1
    Pretty much the same as starting an `Activity`. You use the `startActivity()` method of [`Context`](http://developer.android.com/reference/android/content/Context.html#startActivity%28android.content.Intent%29). – Onik Mar 12 '16 at 14:52
  • but the main class is extends BroadcastReceiver not activity ? – Yanshof Mar 12 '16 at 14:54
  • 1
    And you have `Context` at your disposal in `onReceive()`, so use it as per the answer. – Onik Mar 12 '16 at 14:55
  • I still dont understand - can you please explain – Yanshof Mar 12 '16 at 14:59
  • i still need to extends from Activity in my main class ? – Yanshof Mar 12 '16 at 15:00
  • 2
    No! Look at the accepted answer of your previous question. What you have is a `BroadcastReceiver` and `Service` declared in the manifest (no `Activity`). System gets an sms, creates an instance of the receiver passing `Context` as parameter of `onReceive()`. You then use it to whatever you want as per the docs: start a 3d party app's `Activity` with `startActivity()`, start the service of your app with `startService()` etc. – Onik Mar 12 '16 at 15:05