Widgets configured with android:configure will receive onUpdate even if configuration is unfinished

前端 未结 3 1805
半阙折子戏
半阙折子戏 2021-02-14 14:35

This is how I configure my APP\'s widget:



        
3条回答
  •  耶瑟儿~
    2021-02-14 15:06

    Here is how you handle this: In your configuration activity, do this in your onCreate(): setResult(Activity.RESULT_CANCELED);

    Once the configuration activity is done, e.g. all parameters are set and widget should be shown, do setResult(Activity.RESULT_OK);

    So, if the user does not finish the configuration activity, your widget is removed.

    However, in the widget code itself (onUpdate), you still need to check whether configuration is complete, because APPWIDGET_UPDATE will definitely be called before configuration completion. You can just skip all updating altogether if configuration is not there, your widget will not be visible at this point anyway, and once configuration is complete, your widget is either removed by the system or its configuration is there.

    One more thing. You need to initiate widget update from your configuration activity upon successful completion, because the system will not do it by itself.

提交回复
热议问题