0

我有一个不会捕获 if 块的活动类。因为我是初学者,所以我想不出任何其他方法来捕获给定的 userID("001") 以在 Splash Thread 之后启动特定的意图 (AdminTab)。

有人可以帮我指出我做错了什么或用一些示例代码给我建议吗?谢谢!

公共类 Splash 扩展 Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {

    final UserFunctions userFunction = new UserFunctions();

    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    Thread timer = new Thread(){

    public void run(){

    String id = "";
    id = userFunction.getID(getApplicationContext());

    try{
        sleep(1000);
        //Should open AdminTab if user id is "001"      
        if("001".equals(id)){

        Intent i = new Intent(getApplicationContext(), 
                    AdminTab.class);

                    startActivity(i);

        }else{

        Intent i = new Intent(getApplicationContext(), 
                    UserTab.class);

                    startActivity(i);
        }

        } catch (InterruptedException e){
        e.printStackTrace();
        }finally {


        }
    }

    };

    timer.start();
}

这是来自 UserFunctions 类的 getID 方法。从 sqlite 数据库处理程序中获取用户 ID。

用户函数.java

public String getID(Context context) {
    String id = "";
    DatabaseHandler db = new DatabaseHandler(context);
    Cursor cursor = db.getUserID();

    if(cursor != null) {
        while(cursor.moveToNext()) {
            id = cursor.getString(0);
        }
    } else {
        id = "";
    }

    cursor.close();
    db.close();
    return id;
}
4

2 回答 2

0

您的代码应该可以正常工作,您是否遇到错误?

也许将其更改为 id.equals("001")

如果这不是主要活动,为什么不根据需要在意图中发送 id?

我不完全确定问题是什么。

于 2012-10-30T04:40:27.127 回答
0

“001”.equals(id) 中没有问题。

请检查您从 getID() 获得的 id。您从数据库中获取的 id 存在一些问题。尝试打印值并交叉检查。

于 2012-10-30T05:20:19.017 回答