Android: launchMode="singleTop"
Android: label="This is FirstActivity" & gt;
Will create a new instance after start the application, and I hit the button a few times to press back several times to exit the program
CodePudding user response:
Singletop mode: system found FirstActivity instance, but not in the stack, and to generate an instance,This is singleTop boot mode, if found to have the corresponding Activity instance is located at the top, repeated use, no longer generate a new instance
http://blog.csdn.net/liuhe688/article/details/6754323/
CodePudding user response:
I also met the problem why android: launchMode="singleTop" didn't workCodePudding user response:
Solution: in the oncreate method of adding method: rewrite intent. SetFlags (intent. FLAG_ACTIVITY_SINGLE_TOP);The general method is:
@ Override
Protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
The d (" FirstActivity111 ", enclosing the toString ());
The setContentView (R.l ayout. First_layout);
The Button for the=(Button) the findViewById (R.i db utton_1);
For the setOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View v) {
Intent Intent=new Intent (FirstActivity. This, FirstActivity. Class);
Intent. SetFlags (intent. FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
}
});
}
CodePudding user response:
FirstActivity button click event in the event it is no problem ofIntent Intent=new Intent (FirstActivity. This, ThirdActivity. Class);
startActivity(intent);