내 애플리케이션에는 5 가지 활동 (A1, A2, A3, A4, A5)이 있습니다. 각 활동에는 하나의 텍스트보기와 하나의 단추 (B1, B2, B3, B4, B5)가 있습니다. 해당 버튼을 클릭하면 다음 활동으로 이동합니다. B1 버튼을 클릭하면 A2 활동으로 이동하고 각 활동에는 하나의 메뉴 버튼 (로그 아웃)이 있습니다. 버튼을 클릭하면 응용 프로그램에서 빠져 나옵니다. 하지만 작동하지 않습니다. 여기 나는 모든 활동 호출에 대해 다음 코드를 사용하고 있습니다. 분명히 들어android - 애플리케이션에서 로그 아웃하는 방법
스택은 로그 아웃 버튼 클릭 리스너에서
Intent intent = new Intent(act1.this,act2.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
, 난 그냥 완료 이유 FLAG_ACTIVITY_CLEAR_TOP
를 사용하여 스택이 지금 스택은 그게 전부 현재 활동을 포함 우리가 분명 .because finish()
을 사용하여 현재 활동 완료 현재 활동. 그러나 로그 아웃 버튼을 클릭하면 현재의 행동이 끝납니다. 응용 프로그램을 종료하지 않습니다. 여기서 스택은 지워졌는지 여부는 해당 명세서 FLAG_ACTIVITY_CLEAR_TOP
입니다. 다음은 내 코드가 아무도 나를 도울 수 있습니다.
Actvity 하나
public class logout extends Activity
{
TextView tv;
Button next;
public static final int logout_menu = Menu.FIRST+1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView) findViewById(R.id.text);
tv.setText("activity1");
Button next = (Button) findViewById(R.id.button);
next.setOnClickListener(nextListener);
}
private OnClickListener nextListener = new OnClickListener()
{
public void onClick(View v)
{
try
{
Intent intent = new Intent(logout.this,act2.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
catch(Exception ex2)
{
System.out.println("Not able to launch Registration Screen"+ex2.toString());
}
}
};
public boolean onCreateOptionsMenu(Menu menu){
// TODO Auto-generated method stub
boolean result = super.onCreateOptionsMenu(menu);
menu.add(0, logout_menu, 0, "Logout");
return result;
}
public boolean onOptionsItemSelected(MenuItem item){
// TODO Auto-generated method stub
switch (item.getItemId()) {
case logout_menu:finish();
break;
}
return super.onOptionsItemSelected(item);
}
}
Actvity2
public class act2 extends Activity
{
TextView tv;
Button next;
public static final int logout_menu = Menu.FIRST+1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView) findViewById(R.id.text);
tv.setText("activity2");
Button next = (Button) findViewById(R.id.button);
next.setOnClickListener(nextListener);
}
private OnClickListener nextListener = new OnClickListener()
{
public void onClick(View v)
{
try
{
Intent intent = new Intent(act2.this,act3.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
catch(Exception ex2)
{
System.out.println("Not able to launch Registration Screen"+ex2.toString());
}
}
};
public boolean onCreateOptionsMenu(Menu menu){
// TODO Auto-generated method stub
boolean result = super.onCreateOptionsMenu(menu);
menu.add(0, logout_menu, 0, "Logout");
return result;
}
public boolean onOptionsItemSelected(MenuItem item){
// TODO Auto-generated method stub
switch (item.getItemId()) {
case logout_menu:finish();
break;
}
return super.onOptionsItemSelected(item);
}
}
감사
당신이 열 때마다finish()
와 당신의 활동 (모두)
을 닫아야 할
아직도 물어볼 수없는 경우. –
여기 R.id.common_menu_logout이란 무엇입니까? – naresh
내 resultCode입니다. 정수를 상수로 사용할 수 있습니다. "setResult (100)"을 사용하고 onActivityResult에서 "case 100 :"으로 시도하십시오. –