Android活动无响应,直到按下后退按钮
问题描述:
下面是我的活动的创建。我的问题是,当活动开始时,它完全没有响应,直到我按下后退按钮。一旦我按下后退按钮,它完美的作品。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;
}
答
两两件事:
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
很明显,UI踩点会停下来。你检查了哪一行代码UI线程停止后? – eleven 2015-02-24 12:04:15
我刚刚弄明白了哈哈。典型!被调用的对话框功能不能正确解除对话框。无论如何感谢您的光临。 – jampez77 2015-02-24 12:05:35