Muller
Muller

Reputation: 59

Android Activity Update

I am calling an activity from within itself - basically i've a list of new storys and two filter buttons that when clicked restart the activity with an intent passed that changes the news stories.

When i run the app it works, but for a second i get the old activity UI while the app reads from the new xml feed and then the UI updates. Is there any way to stop this from happening and get the activity to restart cold.

here's the code I am currently attaching to the onclicklistener

public void openFootballNews(View v) {
 Intent i = new Intent(this, News_Landing.class); // News_landing class is the class this code is in
 Bundle bundle = new Bundle();
     bundle.putString("code", "football"); // this, if set, changes the xml feed to read
     i.putExtras(bundle);
     i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
     this.onCreate(null); //this has halved the time the old UI is on the screen for but I cant get rid of it completely
     startActivity(i);
}

any help would be great, thanks!

Upvotes: 1

Views: 2868

Answers (1)

Cheezmeister
Cheezmeister

Reputation: 4985

Starting an activity from itself doesn't make much sense (unless your aim is to do something esoterically recursive ;) ). Also, I may be mistaken, but I believe activities are kept in a stack so that as you flip between news stories, you're piling up one nearly-identical activity after another. I'd similarly think calling onCreate() by hand is bad form.

Would need to see all of your code, but my guess is that you are reading your feed and creating your list inside onCreate(), and that your best bet is to refactor that into a openNews(String sport) method, which you call once in onCreate() and again in your listener(s).

Upvotes: 3

Related Questions