How to start Activity from Android AppWidget?

后端 未结 3 1279
眼角桃花
眼角桃花 2021-01-11 13:48

Code like this works well.

    Intent configIntent = new Intent (context, WidgetConfigActivity.class);
    configIntent.putExtra(AppWidgetManager.EXTRA_APPWI         


        
3条回答
  •  孤街浪徒
    2021-01-11 14:27

    Thanks 2 CommonsWare

    There is one more thing to do. context.startActivity(); throws RuntimeException in this case.

    Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

    So you need to set flag

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    

    before.

提交回复
热议问题