Skip to content

Instantly share code, notes, and snippets.

@caspian311
Created December 15, 2010 12:52
Show Gist options
  • Save caspian311/741910 to your computer and use it in GitHub Desktop.
Save caspian311/741910 to your computer and use it in GitHub Desktop.
found that the lifecycle of an activity was annoying so i use this to navigate between the different pages/activities of my android app
import java.io.Serializable;
import java.util.Collections;
import java.util.Map;
import android.app.Activity;
import android.content.Intent;
public class PageNavigator {
private final IntentFactory intentFactory;
private final Activity homeActivity;
public PageNavigator(Activity homeActivity) {
this(new IntentFactory(), homeActivity);
}
public PageNavigator(IntentFactory intentFactory, Activity homeActivity) {
this.intentFactory = intentFactory;
this.homeActivity = homeActivity;
}
public void navigateToActivity(Class<? extends Activity> targetActivity) {
navigateToActivity(targetActivity, Collections.<String, Serializable>emptyMap());
}
public void navigateToActivity(Class<? extends Activity> targetActivity, Map<String, Serializable> extras) {
Intent intent = intentFactory.createIntent(homeActivity, targetActivity);
for (String key : extras.keySet()) {
intent.putExtra(key, extras.get(key));
}
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
homeActivity.startActivity(intent);
homeActivity.finish();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment