07-18 16:34:05.891: E/AndroidRuntime(18396): FATAL EXCEPTION: main
07-18 16:34:05.891: E/AndroidRuntime(18396): android.util.AndroidRuntimeException:
Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
07-18 16:34:05.891: E/AndroidRuntime(18396): at android.app.ContextImpl.startActivity(ContextImpl.java:971)
07-18 16:34:05.891: E/AndroidRuntime(18396): at android.content.ContextWrapper.startActivity(ContextWrapper.java:283)
07-18 16:34:05.891: E/AndroidRuntime(18396): at com.txrj.sms.service.ReceiveMsgService$1.handleMessage(ReceiveMsgService.java:37)
07-18 16:34:05.891: E/AndroidRuntime(18396): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 16:34:05.891: E/AndroidRuntime(18396): at android.os.Looper.loop(Looper.java:137)
07-18 16:34:05.891: E/AndroidRuntime(18396): at android.app.ActivityThread.main(ActivityThread.java:4517)
07-18 16:34:05.891: E/AndroidRuntime(18396): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 16:34:05.891: E/AndroidRuntime(18396): at java.lang.reflect.Method.invoke(Method.java:511)
07-18 16:34:05.891: E/AndroidRuntime(18396): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
07-18 16:34:05.891: E/AndroidRuntime(18396): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
07-18 16:34:05.891: E/AndroidRuntime(18396): at dalvik.system.NativeStart.main(Native Method)
在ReceiveMsgService(extends Service)中,添加addFlags()方法。
Intent it = new Intent(mContext, ShowSmsActivity.class);
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(it);