2014-03-12 2 views
1

여기 내 code.but이 내 애플 리케이션을 실행하면 60seconds.but에서 다시 애플 리케이션 icon.its 로그 아웃으로 열립니다. 로그 아웃과 애플 리케이션을 닫으려면 열려. 내 서비스 클래스에 이들을 추가했습니다.android 응용 프로그램에서 로그 아웃하는 방법.?

public class BackgroundService extends Service { 
private int interval3 = 10; // 10 seconds 

private Handler mTimer3 = new Handler(); 
private Runnable mTask3 = new Runnable() { 
    public void run() { 
     mTimer3.postDelayed(this, interval3 * 1000L); 
     CountDownTimer timer = new CountDownTimer(10*1000, 1000) { 

      public void onTick(long millisUntilFinished) { 
       Log.w("Seconds remaining: ", String.valueOf(millisUntilFinished/1000)); 
      } 

      public void onFinish() { 
       Intent intent = new Intent(Intent.ACTION_MAIN); 
       intent.addCategory(Intent.CATEGORY_HOME); 
       intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
       startActivity(intent); 
      } 
     }; 
     timer.start();   
    } 
}; 

public void onCreate() { 
    mTimer1.postDelayed(mTask1, interval1 * 1000L); // start the timer for the first time 
    mTimer2.postDelayed(mTask2, interval2 * 1000L); // start the timer for the first time 
    mTimer3.postDelayed(mTask3, interval3 * 1000L); // start the timer for the first time 
} 

제안 사항을 알려주세요. 더 이상 유휴 상태 일 때 앱에서 로그 아웃해야하기 때문에. 덕분에 모든 지금

+1

:-) 나를 위해 page.now의 작업 perrfect가는 로그인 화면 이후에 코드를 추가 신임장에 서명 했어? –

+1

당신은 당신의 활동에서 onPause 또는 onResume 메소드를 오버라이드하고 그것들 중 하나에서 로그 아웃해야 할 수도 있습니다 – Athanor

+0

@Siddharth Vyas, 아직 당신의 포인트 친구가 없습니다 –

답변

0

의 괜찮은가 대신 서비스 클래스의 활동 클래스를 시도하고 난 당신이 저장 할

public class #MyActivityClass extends Activity { 


    //============================================================================================================================= 
    private Handler mTimer3 = new Handler(); 
    private Runnable mTask3 = new Runnable() { 
     public void run() { 
      CountDownTimer timer = new CountDownTimer(10*1000, 1000) { 

       public void onTick(long millisUntilFinished) { 
        Log.w("Seconds remaining: ", String.valueOf(millisUntilFinished/1000)); 
       } 

       public void onFinish() { 
            //Here finally added finish(); and System.exit(0); methods 
        Intent intent = new Intent(Intent.ACTION_MAIN); 
        intent.addCategory(Intent.CATEGORY_HOME); 
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);//***Change Here*** 
        startActivity(intent); 
        finish(); 
        System.exit(0); 
       } 
      }; 
      timer.start(); 
      mTimer3.postDelayed(this, interval3 * 1000L); 
     } 
    }; 

    private int interval3 = 10*60; // 60 seconds 

    @Override 
    protected void onDestroy() { 
     if (mTimer3 != null) { 
      mTimer3.removeCallbacks(mTask3); // cancel the timer 
     } 
    } 
관련 문제