Android - Samsung: Creating Widget with configuration activity fails

橙三吉。 提交于 2019-12-02 06:02:41

From testing on my own Samsung devices, it seems the problem is that TouchWiz chokes if the result Intent doesn't have the App Widget ID attached, even if it's RESULT_CANCELLED.

From the App Widget developer page:

  • The App Widget host calls the configuration Activity and the configuration Activity should always return a result. The result should include the App Widget ID passed by the Intent that launched the Activity (saved in the Intent extras as EXTRA_APPWIDGET_ID).

It's unclear how exactly you wish to ultimately handle the result, but it's definitely a good idea to go ahead and set a valid result in onCreate(), in case the user backs out of the configuration Activity. For example:

final int id = getIntent().getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, 0);
final Intent result = new Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
setResult(RESULT_OK, result);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!