/**********************************************************************************/
package com.cs.dxm.activity04; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; import android.view.Menu; import android.view.MenuItem; import android.widget.Button; public class Activity04 extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_04); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); System.out.println("First Activity->On Create"); Button myButton = (Button)findViewById(R.id.myButton); myButton.setText("Open Other Activity"); myButton.setOnClickListener(new MyButtonListener()); } class MyButtonListener implements View.OnClickListener{ @Override public void onClick(View v) { Intent intent = new Intent(); intent.putExtra("testIntent","123"); intent.setClass(Activity04.this,OtherActivity.class); Activity04.this.startActivity(intent); } } @Override protected void onStart() { super.onStart(); System.out.println("First Activity->on Start"); } @Override protected void onResume() { super.onResume(); System.out.println("First Activity->on Resume"); } @Override protected void onRestart() { super.onRestart(); System.out.println("First Activity->On Restart"); } @Override protected void onPause() { super.onPause(); System.out.println("First Activity->On Pause"); } @Override protected void onStop() { super.onStop(); System.out.println("First Activity->on Stop"); } @Override protected void onDestroy() { super.onDestroy(); System.out.println("First Activity->on Destroy"); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_activity04, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
/***************************************************************************************/
package com.cs.dxm.activity04; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; public class OtherActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_other); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); System.out.println("Other Activity->on Create"); } @Override protected void onStart() { super.onStart(); System.out.println("Other Activity->on Start"); } @Override protected void onResume() { super.onResume(); System.out.println("Other Activity->on Resume"); } @Override protected void onRestart() { super.onRestart(); System.out.println("Other Activity->On Restart"); } @Override protected void onPause() { super.onPause(); System.out.println("Other Activity->On Pause"); } @Override protected void onStop() { super.onStop(); System.out.println("Other Activity->on Stop"); } @Override protected void onDestroy() { super.onDestroy(); System.out.println("Other Activity->on Destroy"); } }
/*****************************************************************************************/
I/System.out: First Activity->On Create
I/System.out: First Activity->on Start
I/System.out: First Activity->on Resume
I/System.out: Other Activity->on Create
I/System.out: Other Activity->on Start
I/System.out: Other Activity->on Resume
I/System.out: First Activity->on Stop
I/System.out: Other Activity->On Pause
I/System.out: First Activity->On Restart
I/System.out: First Activity->on Start
I/System.out: First Activity->on Resume
I/System.out: Other Activity->on Stop
I/System.out: Other Activity->on Destroy
I/System.out: First Activity->On Pause
I/System.out: First Activity->on Stop