Widget not deleted when passing RESULT_CANCELED as result for configuration activity

后端 未结 4 1580
庸人自扰
庸人自扰 2020-12-24 03:07

I have some problems with my widgets. Here is the description:

Context:

I have a home widget.

When I add it, it pops a configuration

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-24 03:44

    I had this same problem, i did this on the onPause event

    public void removeWidget(int appWidgetId) {
        AppWidgetHost host = new AppWidgetHost(Config.this, 1);
        host.deleteAppWidgetId(appWidgetId);
    }
    

    Checked the widget ids, the widget is removed. The host id is not important if you only have one app widget host.

    private boolean canceled = true;
    
    @Override
    protected void onPause() {
        if(canceled) {
            removeWidget(appWidgetId);
        }
        super.onPause();
    }
    

    In the OK click, i set the canceled false

提交回复
热议问题