Skip to content Skip to sidebar Skip to footer

How To Return To Previous Activity From About With A Button Click?

Im trying to return from the about dialog to the main activity by a button click: public class AboutActivity extends Activity implements OnClickListener{ @Override protected void o

Solution 1:

From what I can see in your code, you don't have a button attached to your onClick() method. You can do this two ways, in xml or programmatically.

In xml

<Button
...
android:onClick="functionName"/>

Then in your code, define your function which you named in your xml

public void functionName(View v)
{
  // some codefinish();
}

Programmatically, declare your button

ButtonaBtn= (Button) findViewById(R.id.button_id);
aBtn.setOnClickListener(newOnClickListener() {         
    @OverridepublicvoidonClick(View v)
    {
      // some code
      AboutActivity.this.finish()
    }
});

If you have already attached your button to the onClick() in some way not shown then you may be finishing your main activity. In which case, describe what happens when you click the button and show your Main Activity

Docs for OnClickListener()

Solution 2:

It seems like you have already finished; your previous Activity. Remove finish() from MainActivity where you got to your aboutActiivty.

Solution 3:

You can call onBackPressed() function on btnclick and then can define the following code at end in your class:

@OverridepublicvoidonBackPressed() {
        super.onBackPressed();
        Intentintent=newIntent(this, YourActivity.class);
        startActivity(intent);
    }

hope this will help you.

Post a Comment for "How To Return To Previous Activity From About With A Button Click?"