开发者

Problem in killing activity

I have developed a small android app with 3 activities. In first activity there has a button(Next_Button). If i click the button then the second activity will appear. In second activity there also a button which will forward to third activity after clicking it. In third activity there is a button (Home_Button). If i click this button(Home_Button) then first activity will appear. Now i want to kill sec开发者_开发百科ond activity when i click the Home_Button in the third activity to make first activity visible. How can i do this? Please help.

Best wishes Md. Fazla Rabbi


In third activity, write the below code for your Home button click event:

  btnHome.setOnClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                startActivity(new Intent(this, firstActivity.class)
                 .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            }

        });

For example, for back key pressed, we can override onBackPressed function:

@Override
public void onBackPressed() {
 startActivity(new Intent(this, first firstActivity.class)
 .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
 return;
}

Update:

For your reference, this one is the same as your requirement: Android Intent.FLAG_ACTIVITY_SINGLE_TOP AND Intent.FLAG_ACTIVITY_CLEAR_TOP,

And one more example: Go home feature with FLAG_ACTIVITY_CLEAR_TOP


You don't need to "kill" your activity. In your third activity, if you start the first one with startActivity, you first activity will be shown.

The system will decide if your second activity (or your third) should be paused or destroyed.


just call finish() method of the second activity on Home button click.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜