문제

There are a few times when the user presses the back button on my app, and unfortunately he doesn't get out; the activity slides, but behind it there is exactly the same one...How is that possible? How could I avoid it? should I implementate something for the onBackPressed() method? Thanks for your advices.

도움이 되었습니까?

해결책

You don't have to do implement onBackPressed. This sounds like multiple instances of the activity are being created/started, which is expected default behaviour when calling .startActivity() Check out the docs Tasks and Back Stack. You could use singleTop as the launchmode or set the Intent.FLAG_ACTIVITY_SINGLE_TOP on the intent that launches the activity.

Intent detailsIntent = new Intent(mContext, DetailsActivity.class);
detailsIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
startActivity(detailsIntent);

다른 팁

you can use android:launchMode="singleTop" your activity deceleration in the Manifest .

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top