启动活动时出现Android问题

时间:2014-01-27 18:36:48

标签: android sqlite quit

您好我的应用程序存在一个小问题。

启动活动连接到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);
}

问题在于,当我再次启动时,它不会因所需的活动而改变。例如,如果我已将其更改为不使用该引脚,那么它应该转到主页活动,但相反,它仍然要求登录。如果我不登录,而是,如果我再次使用返回按钮,下次启动应用程序时,它会转到主页而不需要登录。

如果我没有登录并且我想登录,也会发生同样的情况。

如果我在更新设置后转到任务管理器并强制退出它,那么它可以正常工作。

1 个答案:

答案 0 :(得分:0)

所以我已经弄明白了这个问题。

在将android:launchMode="singleTask"添加到开始活动后的清单上,它解决了我的问题。

感谢Chris,我能够更多地关注Manifest以找出错误。

相关问题