Jaison Joseph Jaison Joseph - 2 months ago 6
Android Question

How to open main activity from second activity?

I have a imageButton in my second activity , when i press that button it should go to my main activity, how can i do this ?

ImageButton imageButton=(ImageButton)findViewById(R.id.imageButton5);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Here is the code for go to main activity
}
});

Answer

Use intent for start activities..

ImageButton imageButton=(ImageButton)findViewById(R.id.imageButton5);
    imageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(this, mainActivity.class);
            startActivity(intent);
        }
});
Comments