2014-01-27 45 views
0

你好我的應用程序有一個小問題。開始活動時的Android問題

開始活動連接到sqlite數據庫並檢索一個整數,它會檢查後者是否爲0,1或2.根據編號,它將打開相應的活動。

final DatabaseHandler db = new DatabaseHandler(this); // Connection to the DB 
final GokeyPin pinrow = db.getPin(1); // Grabs Pin + Pin Check + ID 
int pin_check = pinrow.getYN(); //Grabs Pin Check | 0 = Never made a Pin | 1 = Has a pin | 2 = Doesn't want to have pin activated 

    //Checks if you have created a pin 

    if(pin_check==0) { 

     // If 0 that means you haven't created a pin, so it brings you to the Createpin activity 
     Intent intent = new Intent(Start.this, Createpin.class); 
     startActivity(intent); 

    }   

    // Checks if you have the pin active. 

    if(pin_check==1) { 
     // If 1 that means you want to use a pin and you have a pin. Goes to LogIn activity 
     Intent intent2 = new Intent(Start.this, Login.class); 
     startActivity(intent2); 
    } 

    // Now it checks if you don't want to use a pin. That is 2. If so, it goes to Home activity 

    if(pin_check==2) { 
     Intent intent3 = new Intent(Start.this, Home.class); 
     startActivity(intent3);    
    } 

然後我在設置活動更新從設備的返回按鈕SQLite的數量,我退出。

//In setting, checks if you have option to use or not a PIN 
      RadioGroup radioGroup2 = (RadioGroup) findViewById(R.id.radioGroupUsePin); 
      int id2 = radioGroup2.getCheckedRadioButtonId(); 

      if (id2 == -1){ 
       //no item selected 
      } 

      //If user has option NO selected 

      if (id2 == R.id.radioUPNo){ 
       // Grabs Pin + Pin Check + id from DB 
       final GokeyPin pinrow2 = db.getPin(1); 
       //Updates Pin check -> 2 = mean not using 
       pinrow2.setYN(2); 
       db.updatePin(pinrow2);  
      } 
        // If Yes is selected 
      if (id2 == R.id.radioUPYes){ 

         // Grabs Pin + Pin Check + id From DB 
         final GokeyPin pinrow2 = db.getPin(1); 
         //Updates Pin check - 1 = means using pin 
         pinrow2.setYN(1); 
         db.updatePin(pinrow2); 
      } 

然後應用保存更改並使用我的返回按鈕

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

     moveTaskToBack(true); 
     return true; 
    } 
    return super.onKeyDown(keyCode, event); 
} 

的問題是,當我再次啓動它,它不會更改活動想退出應用程序。例如,如果我已將其更改爲不使用引腳,那麼它應該轉到家庭活動,但相反,它仍然要求登錄。如果我沒有登錄,但是如果我再次使用返回按鈕,則下一次啓動應用程序時,它會在沒有要求登錄的情況下進入家中。

如果我沒有登錄並且我想登錄,會發生同樣的情況。

如果我在更新設置後進入任務管理器,並強制退出它,那麼它工作正常。

+0

你在哪裏保存數據?你在哪裏恢復? –

+0

我不確定我們如何在沒有看到代碼的情況下幫助您。 –

+0

「問題是,當我再次啓動它時,它並不會改變所需的活動,而是保持不變,但如果我再次退出而不更改設置活動,則它會改變。」 。精心製作 – gaurav5430

回答

0

所以我想出了這個問題。

在將android:launchMode="singleTask"添加到開始活動後的清單上,它解決了我的問題。

感謝Chris,我能夠更多地關注Manifest以找出錯誤。