Created
January 8, 2024 12:49
-
-
Save sunmeat/23953e89d8250aa5dc8791fc31325ae1 to your computer and use it in GitHub Desktop.
logs + save state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sunmeat.myapplication; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.Toast; | |
import androidx.appcompat.app.AppCompatActivity; | |
public class MainActivity extends AppCompatActivity { | |
String TAG = "life"; | |
int count = 0; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
Button b = findViewById(R.id.button1); | |
b.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
count++; | |
Toast.makeText(MainActivity.this, | |
count + " Hello from handler!", | |
Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
Log.i(TAG, "onCreate"); | |
} | |
@Override | |
public void onSaveInstanceState(Bundle outState) { | |
super.onSaveInstanceState(outState); | |
outState.putInt("count", count); | |
Log.i(TAG, "onSaveInstanceState"); | |
} | |
@Override | |
public void onRestoreInstanceState(Bundle savedInstanceState) { | |
super.onSaveInstanceState(savedInstanceState); | |
count = savedInstanceState.getInt("count"); | |
Log.i(TAG, "onRestoreInstanceState"); | |
} | |
@Override | |
protected void onDestroy() { | |
super.onDestroy(); | |
Log.i(TAG, "onDestroy"); | |
} | |
@Override | |
protected void onRestart() { | |
super.onRestart(); | |
Log.i(TAG, "onRestart"); | |
} | |
@Override | |
protected void onStart() { | |
super.onStart(); | |
Log.i(TAG, "onStart"); | |
} | |
@Override | |
protected void onStop() { | |
super.onStop(); | |
Log.i(TAG, "onStop"); | |
} | |
@Override | |
protected void onResume() { | |
super.onResume(); | |
Log.i(TAG, "onResume"); | |
} | |
@Override | |
protected void onPause() { | |
super.onPause(); | |
Log.i(TAG, "onPause"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment