在Application中使用startActivity方法

时间:2025-01-31 07:15:23

在Application中使用startActivity方法

一不下心在Application中使用了startActivity方法,编译器报如下异常(注意Caused by):

: Fatal Exception thrown on Scheduler.
    at $(:111)
    at (:815)
    at (:104)
    at (:224)
    at (:5929)
    at (Native Method)
    at (:372)
    at $(:1113)
    at (:879)
Caused by: : Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

根据Caused by的提示,Activity外部调用startActivity()需要一个flag。

    (Intent.FLAG_ACTIVITY_NEW_TASK)