我有這個活動類,不會趕上if塊。因爲我是初學者,所以我無法想出任何其他方式來捕捉給定的userID(「001」)以在Splash Thread之後啓動特定的意圖(AdminTab)。使用用戶標識啓動意圖,如果塊
有人能幫我指出我做錯了什麼,或者給我一些示例代碼的建議嗎?謝謝!
公共類飛濺延伸活動{
@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數據庫處理程序的getUserID。
UserFunctions.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;
}
謝謝。不,我沒有收到任何錯誤。但就像我說的,它不會捕獲if塊..我已經嘗試過id.equals(「001」),但它沒有奏效。這是飛濺活動的主要活動。 – user1781367