AppWidget Update Service Does Not Stop Removing Widget from Host

What I'm trying to do is when the AppWidget is removed from the main screen of the Android Android phone, I want to stop the background service that updates the AppWidget.

Here is the code I'm using ... don't understand what is wrong?

@Override
 public void onDeleted(Context context, int[] appWidgetIds){
 Intent serviceIntent = new Intent(context, UpdateService.class);
 context.stopService(serviceIntent);
 super.onDeleted(context, appWidgetIds);
}

Any ideas? Thanks for the help.

+3
source share
2 answers

After much research, I finally fixed it. My goal was to stop the background service if all instances of AppWidget were removed from the screen.

Here is what he did ...

  • 1 0. SharePref 1, . 0, .

  • @Override OnReceive . - AppWidget Enabled (, ), AppWidget ( , ) AppWidget Disabled - OnDisabled.

3.In @Override OnDisabled stopService. .

OnDeleted OnDisabled. OnDeleted , , , . , , .

* , Android .., IntentService. **

+5

, onDestroy .

@Override
public void onDestroy() {
    super.onDestroy();
    timer.cancel();
    //Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();

}

timer ist , _startService void

0

Source: https://habr.com/ru/post/1772864/


All Articles