2013-08-05 2 views
0

죄송합니다 다시 버튼을 클릭하십시오. 여기 올바른 배치를 선택하십시오. 나는이 클래스에서 앱이 종료 될 때만 나가기를 원하지만, 정확히 무엇을 쓸 것인지 또는 어디에 쓸 것인지를 파악할 수는 없다. 도와 주셔서 감사합니다. 아래 클래스의 코드. package com.example.whattodo2; 이 같은다시 누를 때 앱 종료

import android.os.Bundle; 
import android.app.Activity; 
import android.content.Intent; 
import android.view.Menu; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.animation.Animation; 
import android.view.animation.AnimationUtils; 
import android.widget.Button; 
import android.widget.ImageView; 
import android.widget.RelativeLayout; 

public class Title extends Activity { 
Button reset, rts; 
ImageView title; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_title); 
    reset = (Button) findViewById(R.id.reset); 
    reset.setOnClickListener(new View.OnClickListener() { 

       @Override 
       public void onClick(View arg0) { 
         double rand = Math.random(); 
         if(rand < 0.5){ 
          Intent reset1 = new Intent(Title.this, MainActivity.class); 
          startActivity(reset1); 
         } else { 
          Intent reset2 = new Intent(Title.this, Question36.class); 
          startActivity(reset2); 
         } 
       } 
      }); 
    rts = (Button) findViewById(R.id.rts); 
    rts.setOnClickListener(new View.OnClickListener() { 

       @Override 
       public void onClick(View arg0) { 
        // TODO Auto-generated method stub 
        Intent rts=new Intent(Title.this,Rts.class); 
        startActivity(rts); 

       } 
      }); 

     final Animation a = AnimationUtils.loadAnimation(this, R.animator.animation); 
     a.reset(); 
     final ImageView rImage = (ImageView) findViewById(R.id.title); 

     RelativeLayout layout = (RelativeLayout) findViewById(R.id.root); 
     layout.setOnClickListener(new OnClickListener() { 

      @Override public void onClick(View v) { 
     rImage.startAnimation(a); 
     func(); //A call to the function. 

     } 
     }); 


} 

protected void func() { 
    // TODO Auto-generated method stub 

} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.title, menu); 
    return true; 
} 

} 

답변

2

사용 :

public class Title extends Activity { 

@Override 
public void onBackPressed() { 
// TODO Auto-generated method stub 

    Intent intent = new Intent(Intent.ACTION_MAIN); 
    intent.addCategory(Intent.CATEGORY_HOME); 
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    startActivity(intent); 

super.onBackPressed(); 
} 
} 

희망이 당신에게 몇 가지 솔루션을 제공 할 것입니다.

모든 활동에서 onCreate 전에
+0

당신이 제안 할 수 있습니다이 긴 점에서 나는이 배치하시기 바랍니다해야 어디? – user2643867

+0

다른 함수처럼 다른 방법으로 넣으십시오. – codeMagic

+0

@ user2643867 내 편집 된 ans를 확인하십시오. 지정된대로 사용하면 – Nirmal

1

:

public boolean onKeyDown(int keyCode, KeyEvent event) { 
    if ((keyCode == KeyEvent.KEYCODE_BACK)) { 

     Intent intent=new Intent (Intent.ACTION_MAIN); 
     intent.addCategory(Intent.CATEGORY_HOME); 
     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     startActivity(intent); 

      // finish(); 
    } 
    return true; 
} 
+0

나는 60 가지 다른 활동을했습니다 ...이 모든 것을 추가하는 데는 시간이 오래 걸릴 것입니다. 더 직접적인 방법이 있습니까? – user2643867

+0

매니페스트에서 nohistory를 true로 사용 하시겠습니까? – Exceptional

+0

아니요 그런 설정이 없습니다. – user2643867