在BroadcastReceiver中啟動Activity: 如果在BroadcastReceiver的onReceive()方法中如下啟動一個Activity Intent intent=new Intent(context,AnotherActivity.class); context.startActivity(intent); 可捕獲異常信息: 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(上下文環(huán)境)之外調(diào)用startActivity()方法時 需要給Intent設置一個flag:FLAG_ACTIVITY_NEW_TASK 所以在BroadcastReceiver的onReceive()方法中啟動Activity應寫為: Intent intent=new Intent(context,AnotherActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); 之前描述了問題的現(xiàn)象和解決辦法,現(xiàn)在試著解釋一下原因: 1 在普通情況下,必須要有前一個Activity的Context,才能啟動后一個Activity 2 但是在BroadcastReceiver里面是沒有Activity的Context的 3 對于startActivity()方法,源碼中有這么一段描述: Note that if this method is being called from outside of an {@link android.app.Activity} Context, then the Intent must include the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because, without being started from an existing Activity, there is no existing task in which to place the new activity and thus it needs to be placed in its own separate task. 說白了就是如果不加這個flag就沒有一個Task來存放新啟動的Activity. 4 其實該flag和設置Activity的LaunchMode為SingleTask的效果是一樣的