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.
From what you have mentioned it doesn’t seem like you need the intent flags.
When you set the
FLAG_ACTIVITY_CLEAR_TOPflag, if the activity to be launched is already running, all other activities on top of it are closed such that the activity being called (which was already running and in the stack) is now on top. Now, when you press the back button, it should go to the activity that was running before this, but since your Main activity was closed because of that flag, you get a blank screen.