错误提示信息:

        Caused by: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

原因:

     activity继承了context重载了startActivity方法,如果使用acitvity中的startActivity,不会有任何限制。

     而如果直接使用context的startActivity则会报上面的错误,根据错误提示信息,可以得知,如果要使用这种方式需要打开新的TASK。

故,解决方法:

   intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

  context.startActivity(intent);

相关文章:

  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2021-05-20
  • 2021-07-15
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-15
  • 2022-12-23
  • 2022-12-23
  • 2021-07-24
  • 2021-10-17
相关资源
相似解决方案