2011年11月1日 星期二

[Android] Start Activity in Service or Content Provider

* 可以在 Service 或 Content Provider 中開啟 Activity,但 Intent 中必須加入 Intent.FLAG_ACTIVITY_NEW_TASK Flag 才行,否則會出現以下錯誤。


* In Service
   ......
java.lang.RuntimeException: Unable to start service com.yellow.android.service.EmptyService@444bde30 with Intent { cmp=TestService}: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
   ......
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?
at android.app.ApplicationContext.startActivity(ApplicationContext.java:560)
   ......


* In Content Provider
   ......
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
at android.app.ApplicationContext.startActivity(ApplicationContext.java:560)
   ......


* Pending Issues
  • Why must sartActivity with new task?
  • Different tasks in an application will have any effects?


Related

沒有留言:

張貼留言