ANR keyDispatchingTimedOut error
ANR Error
Activity Not Responding.
Your activity took to long to say to the Android OS 'hey i'm still alive'! (This is what the UI thread does).
http://developer.android.com/guide/practices/design/responsiveness.html
Basically if you make the UI thread do some complex task it's too busy doing your task to tell the OS that it is still 'alive'.
http://android-developers.blogspot.co.uk/2009/05/painless-threading.html
You should move your XML Parsing code to another thread, then use a callback to tell the UI thread you have finished and to do something with the result.
http://developer.android.com/resources/articles/timed-ui-updates.html
Android app: ANR keyDispatchingTimedOut error
get the error message through data/anr/trace.txt from File explorer. And, also put all logical operations and loops into separate threads.
Another ANR keyDispatchingTimedOut error. But i can't figure out why
First of all, where is select(Card card) called?. This is very important to avoid log operations in main UI thread (standard actions performed in activity e.g. onCreate()).
If you accidentally run some loop, or deadlock happend UI will freeze and ANR will be noticed.
Try to use AsyncTask to play the sound and check the time of method execution. Remember that the slower devices needs more time to perform operations.
Ok, now is see where it is called.
ANR keyDispatchingTimedOut in ActivityManager
You can implement your method as
onStart method
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
doLongerTask();
}
Method which will take long time to do process
private void doLongerTask() {
final ProgressDialog dialog = ProgressDialog.show(Client.this, "Please wait", "Doing long task...", true);
dialog.setCancelable(true);
//dialog = CustomProgressDialog.show(this, "", "");
new Thread() {
@Override
public void run() {
try{
//TODO Write here your method logic
sleep(5000);
} catch (Exception e) {
Log.i("your_app_tag", e.toString());
dialog.dismiss();
}
//Dismiss dialog, and notify handler to done this task
dialog.dismiss();
longTaskHandler.sendEmptyMessage(0);
}
}.start();
}
Handler which will handle UI changes after finishing long process.
private Handler longTaskHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch(msg.what) {
case 0:
//Here you can implement UI code. like if you are using listview
//then you can refresh listview.
break;
}
}
};
This is not only one way. Read here to know all possible ways.
Happy coding :)
Related Topics
What Is the Equivalent of Actionbar in Earlier Sdk Versions
How to Get References for All Currently Active Fragments in an Activity
How to Set Minimum Datepicker Date to Current Date
Android Take Screenshot via Code
Android App Crashes with Sigabrt Signal 6 Only While Eclipse Debugging
Activate an Application When a Power Button Is Clicked
Sqlite Example Program in Android
How to Correctly Start Activity from Postexecute in Android
How to Blur Some Portion of Image in Android
Set Live Wallpaper Programmatically on Rooted Device Android
Adt Blank Activity Created with Fragment Activity
Android:How to Update the Selector(Statelistdrawable) Programmatically
Android Studio: Unable to Start the Daemon Process
Programmatic Screencapture on Mobile Device
Installation Error: Install_Failed_Older_Sdk