Skip to content

Instantly share code, notes, and snippets.

@SyncHack
Created April 1, 2012 06:37
Show Gist options
  • Save SyncHack/2272027 to your computer and use it in GitHub Desktop.
Save SyncHack/2272027 to your computer and use it in GitHub Desktop.
// そうそ、AndroidManifest.xmlに追加するのを忘れないでね。忘れがちだよねえw
public class RecreateActivity extends Activity {
private final static String TAG_RECRIATE_NAME = "recreate_callback_class_name";
public static Intent recreateIntent(Context ctx, String classname, Bundle outState) {
Intent intent = new Intent(ctx, RecreateActivity.class);
outState.putString(TAG_RECRIATE_NAME, classname);
intent.putExtras(outState);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_CLEAR_TOP);
return intent;
}
public static Bundle recreateBundle(Intent intent) {
Bundle bundle = intent.getExtras();
if (bundle == null) {
return null;
}
String classname = bundle.getString(TAG_RECRIATE_NAME);
if (classname == null || classname.length() < 1) {
return null;
}
return bundle;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle outState = getIntent().getExtras();
if (outState == null) {
finish();
return;
}
String pname = outState.getString(TAG_RECRIATE_NAME);
if (pname == null || pname.length() < 1) {
finish();
return;
}
try {
Intent redirect = new Intent(getApplicationContext(), Class.forName(pname));
redirect.putExtras(outState);
redirect.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(redirect);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
overridePendingTransition(0, 0);
finish();
overridePendingTransition(0, 0);
}
}
// ふと思ったんだがこの仕組み、メモリリークのリセットに活用できまいか。ださいけど。
// ライセンスの付加って必要?gistにある時点でほぼfree確定なんだが気にする人は気にするのかな
// 気になるならAPL 2.0で「Copyright (C) 2012 Makoto NARA (Mc.N)」でひとつ。
// まあ自由にしてよ =)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment