How to launch activity from service properly?
I have a activity that can launch a service after the user presses the button. In this service, i have a Timer that runs every 10s. I want to run another activity (google maps) from this service every 10s. If i put it in service i get this 开发者_运维问答error:
12-29 10:09:21.369: ERROR/AndroidRuntime(235): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
Where shoud i put my code to launch activity?
As the error message said, You need set the flag in your Intent
Intent intent = new Intent(MyService.this,MyActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
精彩评论