Skip to content

Instantly share code, notes, and snippets.

@amay077
Created January 21, 2011 09:19
Show Gist options
  • Save amay077/789458 to your computer and use it in GitHub Desktop.
Save amay077/789458 to your computer and use it in GitHub Desktop.
Android で、アプリケーションを終了させても static 変数は生存していることを確認するサンプルコード
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity {
/** static な変数 */
private static int id = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// LogCat に出力
// 起動→終了→起動を繰り返すと id が加算されていく。
Log.d("MainActivity", "static member:" + String.valueOf(id));
id++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment