当前位置: 动力学知识库 > 问答 > 编程问答 >

How can i make a back button to return a previous activity on Android studio? (Without action bar)

问题描述:

So, thats my question, i´ve trying to make a button who gets back to my previous activity on my app, I tried to create an intent but didn´t work.

This is what I tried:

finish();

 Intent intent = new Intent(Activity1.this,Activity2.class);

startActivity(intent);

But as I´ve said , didn´t work , appear me a error message.

Hope you can help me , Thanks.

网友答案:

According to the Android documentation (here), you just need to use finish(); to end your activty, this will automatically go back to the previous activity.

网友答案:

call method onBackPressed()

findViewById(R.id.myButtom).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
});
分享给朋友:
您可能感兴趣的文章:
随机阅读: