Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android app Back button shows blank screen

I have an android app that starts with a simple screen and a "start" a button. Once the user clicks the button it retrieves code from a url and puts it into a list. If you press back from the listview it will show a blank screen not a screen with the "start" button. All the code is in a onCreate statement. Please excuse me if I am missing the obvious this is my first real android app (aside from the Hello Android tutorial). Below is the code in the first activity if that helps.

public class Main extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button next = (Button) findViewById(R.id.butQR);
    next.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            setContentView(R.layout.listplaceholder);
            Intent myIntent = new Intent(view.getContext(), NewListActivity.class);
            myIntent.putExtra("race_id", view.getId());
            myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
            myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(myIntent);
        }

    });
}

Update: I wa using setContentView(R.layout.listplaceholder); on button click and in the new oncreate for the next activity. Thanks for the help.

like image 485
mathius1 Avatar asked Mar 19 '26 01:03

mathius1


1 Answers

You shouldn't be creating a new task for a subactivity, and I see no reason to clear the top of the task stack. If you don't want the start activity to show when the user goes back, you can simply finish() it after starting the new activity.

like image 55
K-ballo Avatar answered Mar 20 '26 15:03

K-ballo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!