Skip to content

Instantly share code, notes, and snippets.

@MohamedRamadanSaad
Created May 19, 2015 20:51
Show Gist options
  • Save MohamedRamadanSaad/8be078c5b692a5635a95 to your computer and use it in GitHub Desktop.
Save MohamedRamadanSaad/8be078c5b692a5635a95 to your computer and use it in GitHub Desktop.
Android Life Cycle
package com.example.second_app;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(MainActivity.this,"Create",Toast.LENGTH_SHORT).show();
get_sec_activity();
}
public void get_sec_activity(){
Button b=(Button)findViewById(R.id.button1);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent i = new Intent(MainActivity.this,target.class);
startActivity(i);
}
});
}
public void onStart(){
super.onStart();
Toast.makeText(MainActivity.this,"START",Toast.LENGTH_SHORT).show();
}
public void onResume(){
super.onResume();
Toast.makeText(MainActivity.this,"Resume",Toast.LENGTH_SHORT).show();
}
public void onPause(){
super.onPause();
Toast.makeText(MainActivity.this,"Pause",Toast.LENGTH_SHORT).show();
}
public void onStop(){
super.onStop();
Toast.makeText(MainActivity.this,"Stop",Toast.LENGTH_SHORT).show();
}
public void onDestroy(){
super.onDestroy();
Toast.makeText(MainActivity.this,"Destroy",Toast.LENGTH_SHORT).show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment