2012-10-30 15 views
0

我有這個活動類,不會趕上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; 
} 

回答

0

您的代碼應該可以正常工作,你得到一個錯誤?

也許它更改爲id.equals(「001」)

如果這不是主要的活動你爲什麼不只是通過在意向發送號碼要求?

我不完全確定問題是什麼。

+0

謝謝。不,我沒有收到任何錯誤。但就像我說的,它不會捕獲if塊..我已經嘗試過id.equals(「001」),但它沒有奏效。這是飛濺活動的主要活動。 – user1781367

0

「001」.equals(id)中沒有問題。

請檢查您從getID()獲得的ID。您從數據庫中獲取的id存在一些問題。嘗試打印該值並進行交叉檢查。