I have a strange problem, I am wanting to launch to the marketplace from my app - am doing the following.
Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
"market://details?id=" + activity.getPackageName()));
try {
activity.startActivity(marketIntent);
} catch (ActivityNotFoundException e) {
Toast.makeText(activity, "Could not launch market", Toast.LENGTH_LONG).show();
}
However when there the user can press Open
again, when they do that I get :
08-22 15:18:37.510: INFO/ActivityManager(260):开发者_高级运维 Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.xyz.appname cmp=com.xyz.appname/.mainapp } from pid 22853
08-22 15:18:37.590: INFO/ActivityManager(260): Starting: Intent { cmp=com.xyz.appname/.secondactivity } from pid 25735
08-22 15:18:37.590: WARN/InputManagerService(260): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@2b49a938
and it never reopens the app , they just stuck there - hitting back does work.
Tracing the code the warning is coming from this in mainapp
:
Intent tabActivity = new Intent();
tabActivity.setClass(this, secondactivity.class);
startActivity(tabActivity);
this.finish();
This definitely looks like an issue with how it is restarted - you're on the right track with that last bit of code.
This flag looks like what you need to tell Android to pull the existing activity off of the history stack and re-use it:
FLAG_ACTIVITY_SINGLE_TOP
Alternatively (if you want to restart rather than resume), maybe you could hint to Android to recycle the activity after you move on, by using this with your intent:
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
精彩评论