簡體   English   中英

在按下返回按鈕之前,Android活動無響應

[英]Android activity unresponsive until back button is pressed

以下是我的活動的oncreate。 我的問題是,當活動開始時,它完全無響應,直到我按下“后退”按鈕。 一旦按下后退按鈕,它就會完美運行。

@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;
}

2件事:

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線程上進行了一些網絡操作,這可能是活動未響應的原因,或者可能與您使用的dialog方法有關。 如果顯示該方法代碼,則可能導致進一步的診斷。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM