h.hejabi
h.hejabi

Reputation: 85

service killed when app cloes just in huawei device

I make service to Toast a text always but just in huawei device service killed when i kill app.
I don't know why?

My service is:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    onTaskRemoved(intent);
    new CountDownTimer(99999999L,5000 ) {
        @Override
        public void onTick(long arg0) {
                Toast.makeText(getApplicationContext(), "hihihi", Toast.LENGTH_LONG).show();
        }

        @Override
        public void onFinish() {
        }
    }.start();
    return START_STICKY;
}

@Override
public IBinder onBind(Intent intent) {
    // TODO: Return the communication channel to the service.
    throw new UnsupportedOperationException("Not yet implemented");
} 

Upvotes: 1

Views: 398

Answers (2)

MarkWalczak
MarkWalczak

Reputation: 1571

An old question, but I think it’s important to know that HUAWEI has a feature called “power-intensive app monitor“.

It kills every app that runs in the background for a long time unless user gives special permissions to it.

The path to do this: Settings -> Security & privacy -> Location services -> recent location requests: YOUR APP NAME -> Battery -> uncheck Power-intensive prompt, App launch: Manage manually: check all three positions: Auto-launch, secondary launch, run in background.

I don’t know if there's a way to do this programmatically. I think the best way is to create a sort of help activity and explain the user what to do if application won’t work.

Upvotes: 1

solamente
solamente

Reputation: 266

You should stop the service on the method @Override onDestroy()

Upvotes: 0

Related Questions