Skip to content

Instantly share code, notes, and snippets.

@bluemyria
Created March 1, 2018 09:58
Show Gist options
  • Save bluemyria/4e5f44ca3e40fdf722d68a83441ec6a5 to your computer and use it in GitHub Desktop.
Save bluemyria/4e5f44ca3e40fdf722d68a83441ec6a5 to your computer and use it in GitHub Desktop.
Android - 005 - Activities Lifecycle / Intents
public class MainActivity extends AppCompatActivity {
private final String KLASSE = "MainActivity";
private Button btnZweiteActivity;
@Override
protected void onStart() {
super.onStart();
Log.v("XXXXX " + KLASSE, "onStart");
}
@Override
protected void onStop() {
super.onStop();
Log.v("XXXXX " + KLASSE, "onStop");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.v("XXXXX " + KLASSE, "onDestroy");
}
@Override
protected void onPause() {
super.onPause();
Log.v("XXXXX " + KLASSE, "onPause");
}
@Override
protected void onResume() {
super.onResume();
Log.v("XXXXX " + KLASSE, "onResume");
}
@Override
protected void onRestart() {
super.onRestart();
Log.v("XXXXX " + KLASSE, "onRestart");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
Log.v("XXXXX " + KLASSE, "onCreate");
}
private void init() {
btnZweiteActivity = findViewById(R.id.btnZweiteActivity);
btnZweiteActivity.setOnClickListener(new myOCL());
}
private class myOCL implements View.OnClickListener {
@Override
public void onClick(View view) {
if( view == btnZweiteActivity) {
ZweiteActivityAufrufen();
}
}
}
private void ZweiteActivityAufrufen() {
// Absicht erzeugen, eine zweite Activity aufzurufen
Intent intent = new Intent(this, ZweiteActivity.class);
// Absicht in die Tat umsetzen
startActivity(intent);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment