Run this code:
public class Activity1 extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button next = (Button) findViewById(R.id.Button01); next.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent myIntent = new Intent(view.getContext(), Activity2.class); startActivityForResult(myIntent, 0); } }); } }
activity 2:
public class Activity2 extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main2); Button next = (Button) findViewById(R.id.Button02); next.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent intent = new Intent(); setResult(RESULT_OK, intent); finish(); } }); }
Also make sure to create 2 different xml in the layout folder and add as an action in the manifest file , e.g.
<activity android:name=".Activity2"></activity>
As shown in the example.
Hope this helps you.
source share