The error is as follows
- 02-10 13:26:11.048: ERROR/AndroidRuntime(17173): 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?
The startActivity method of Context needs to start a new task.
If you use the startActivity method of Activity, there will be no restrictions, because Activity inherits from Context and has overloaded the startActivity method.
Solution:
Add a FLAG_ACTIVITY_NEW_TASK flag as the error prompts
- public void onReceive(Context context, Intent intent) {
- ……
- Intent startiPhone = new Intent(context, Iphone.class);
- startiPhone.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- context.startActivity(startiPhone);
- ……
- }