package com.example.intenttest; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.widget.Button; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button btn1=(Button)findViewById(R.id.b1); btn1.setOnClickListener(new Button.OnClickListener() { public void onClick(View view) { Intent intent=new Intent(); intent.setClass(MainActivity.this,Test.class); startActivity(intent); MainActivity.this.finish(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
package com.example.intenttest; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.widget.Button; public class Test extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test); Button btn2=(Button)findViewById(R.id.b2); btn2.setOnClickListener(new Button.OnClickListener() { public void onClick(View view) { Intent intent=new Intent(); intent.setClass(Test.this,MainActivity.class); startActivity(intent); Test.this.finish(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }