Karma5
Karma5

Reputation: 273

How to make an activity always run in background

I am making an application in which i am using broadcast reciever to call a service. The problem is that I have to open the application to make the service work. I want that just install application and it will run the service automatically.

In the main activity I have used Intent filter and I have made a class for brodcast reciever and called onRecieve method

Upvotes: 2

Views: 1236

Answers (2)

Ajit Singh
Ajit Singh

Reputation: 75

You can use the startforeground() method in your service to avoid getting it killed.

Upvotes: 0

Rohan Kandwal
Rohan Kandwal

Reputation: 9326

If you want to run something in background it should be a Service. It was designed specifically for this purpose. The sole purpose of an Activity is user interaction.

Upvotes: 4

Related Questions