我有一个不会捕获 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;
}