Question

I have a Bus timetable app with a lot of activity (around 120). It is working smoothly, but after opening several activities, it gets slower. So I have buttons that opens an other activity. I want to kill the former activity after the other is opened. How can I make it? Thanks in advance.

My button click action:

addListenerOnButton();
}


public void addListenerOnButton() {

final Context context = this;

button101 = (Button) findViewById(R.id.button101);

button101.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {

        Intent intent = new Intent(context, B10oda.class);
        startActivity(intent);   
    }
});
Was it helpful?

Solution

Call finish()

Intent intent = new Intent(context, B10oda.class);
startActivity(intent);
finish();

But think again if you really want to finish the Activity. You could do some profiling and find out why your app is running slow.

Also 120 Activities seems too much. See if you could change your design and reduce the number of Activities.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top