下面是我的活動的創建。我的問題是,當活動開始時,它完全沒有響應,直到我按下後退按鈕。一旦我按下後退按鈕,它完美的作品。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;
}
很明顯,UI踩點會停下來。你檢查了哪一行代碼UI線程停止後? – eleven 2015-02-24 12:04:15
我剛剛弄明白了哈哈。典型!被調用的對話框功能不能正確解除對話框。無論如何感謝您的光臨。 – jampez77 2015-02-24 12:05:35