2015-02-24 99 views
0

下面是我的活動的創建。我的問題是,當活動開始時,它完全沒有響應,直到我按下後退按鈕。一旦我按下後退按鈕,它完美的作品。Android活動無響應,直到按下後退按鈕

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_packs); 
    count = 0; 

    Bundle extras = getIntent().getExtras(); 
    if(extras != null || !equals("")){ 
     name = extras.getString("name"); 
    } 
    else{name="PackActivity";} 


    //getActionBar().setTitle(name); 
    ActionBar actionBar = getActionBar(); 
    //actionBar.setBackgroundDrawable(R.drawable.navigation_bar_colour_image); 
    //actionBar.setHomeButtonEnabled(true); 
    actionBar.setTitle(name); 

    actionBar.setDisplayHomeAsUpEnabled(false); 
    //actionBar.hide(); 
    database = new DataObjectDataSource(this.getApplicationContext()); 
    //load all the packs from the DB 
    packs = loadPacks(); 
    //make the request for GetPacks 
    sortArrayById(); 

    if(isOnline(this)) { 
     HTTPRequest.getHTTPRequest(HTTPRequest.getPacksURL, this); 
    } 
    else{ 
     dialog("No internet connection available","their is limited functionality available in offline mode",1); 
    } 


    gridView = (GridView) findViewById(R.id.packGrid); 

    adapter = new PackGridAdapter(this, getApplicationContext(), packs); 
    gridView.setAdapter(adapter); 
    gridView.setOnItemClickListener(this); 

    System.out.println(" pack_ids "); 
} 

我已經包含了對話框的功能,因爲它已被解僱後就沒有響應了。

public boolean dialog(String mes,String message,int type){ 
    AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    // Add the buttons 
    if(type==2){ 
     builder.setMessage(message) 
     .setTitle(mes); 
     builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int id) { 

        } 
       }); 
    } 
    // Create the AlertDialog 
    final AlertDialog dialog = builder.create(); 
    dialog.show(); 
    if(type==2){ 
     final Timer t = new Timer(); 
     t.schedule(new TimerTask() { 
      public void run() { 
       dialog.dismiss(); 
       // when the task active then close the dialog 
       t.cancel(); // also just top the timer thread, otherwise, you may receive a crash report 
      } 
     }, 5000); 

    } 
    return true; 
} 
+0

很明顯,UI踩點會停下來。你檢查了哪一行代碼UI線程停止後? – eleven 2015-02-24 12:04:15

+0

我剛剛弄明白了哈哈。典型!被調用的對話框功能不能正確解除對話框。無論如何感謝您的光臨。 – jampez77 2015-02-24 12:05:35

回答

1

兩兩件事:

1日確認您的ActionBar代碼工作或(發表意見actionbar部分,以確保不在這裏元兇),看看如果該活動是響應不

如果第一次不工作,甚至評論後ActionBar活動反應遲鈍..然後

第二個評論這幾行:

if(isOnline(this)) { 
    HTTPRequest.getHTTPRequest(HTTPRequest.getPacksURL, this); 
} 
else{ 
    dialog("No internet connection available","their is limited functionality available in offline mode",1); 
} 

我懷疑你在UI線程上做了一些網絡操作,這可能是Activity not Responding的原因,或者它與你使用的dialog方法有關。如果顯示該方法代碼,可能會導致進一步診斷。

+1

我剛剛弄明白了。我的對話框功能並沒有正確地解除對話框。儘管你在正確的路線上。感謝您的期待。 – jampez77 2015-02-24 12:07:39