以下のコードを確認してください:私は3つのアクティビティを持っています:MainActivity、A_Acvitiy、B_actiivty(あなたの要件に従ってうまくいくことを願っています..)
package com.example.androidtest;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void callActivity(View v) {
if (v.getId() == R.id.button1) {
// A
startActivity(new Intent(MainActivity.this, A_activity.class));
}
if (v.getId() == R.id.button2) {
// B
startActivity(new Intent(MainActivity.this, B_activity.class));
if (GeneraClass.isFormB) {
GeneraClass.isFormB = false;
finish();
}
}
}
}
A_アクティビティ:
package com.example.androidtest;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class A_activity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.a_layout);
}
public void callActivity(View v) {
if (v.getId() == R.id.button1) {
// B
startActivity(new Intent(A_activity.this, B_activity.class));
finish();
}
}
}
b_アクティビティ:
package com.example.androidtest;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class B_activity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.b_layout);
}
public void callActivity(View v) {
if (v.getId() == R.id.home) {
// home
GeneraClass.isFormB = true;
startActivity(new Intent(B_activity.this, MainActivity.class));
finish();
}
}
}
私の余分なクラス:
package com.example.androidtest;
public class GeneraClass {
public static boolean isFormB = false;
}
そう、Home-->A(finish)-->B--->Home(if from b then finish)-->B-->Back--> Home --->Back--> exit App