top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Android: I am receiving ANR notification sometimes in my application, how can I prevent showing this message?

+2 votes

I am receiving ANR notification sometimes in my application. The code is working fine though, how can I prevent showing this message. Please help.

posted Jul 5, 2016 by Shalini

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

I assume the ANR you are referring to is App Not Responding.
The reason you receive ANR notification is that the app is working too much on it's main thread. If you are going to perform any complex operation (time consuming) then you should probably use a separate thread for it. Doing so you will not freeze your main thread.

An example code for

private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
    // Do the long-running work in here
    protected Long doInBackground(URL... urls) {
        int count = urls.length;
        long totalSize = 0;
        for (int i = 0; i < count; i++) {
            totalSize += Downloader.downloadFile(urls[i]);
            publishProgress((int) ((i / (float) count) * 100));
            // Escape early if cancel() is called
            if (isCancelled()) break;
        return totalSize;

    // This is called each time you call publishProgress()
    protected void onProgressUpdate(Integer... progress) {

    // This is called when doInBackground() is finished
    protected void onPostExecute(Long result) {
        showNotification("Downloaded " + result + " bytes");

new DownloadFilesTask().execute(url1, url2, url3); //Your call

Official documentation is here

answer Jul 7, 2016 by Vinod Kumar K V
Similar Questions
+1 vote

Where can I find the code that takes care of the "notification panel revealed" (notification curtain down) event?
Id like to understand the logic that control the order of appearance of the notifications once you swipe down the curtain...

+1 vote

I working on a project which needs adding a service with JNI to the system server and also a new daemon in init.rc script. I have successfully done this.
I might need the system service to periodically send SIGUSR1/2 signals to the daemon. Linux requires a sender of signals to be root. Do I have this privilege inside system server in Android?

+2 votes

I want to open another application from my application. I know I should use Intent for that, but I am not sure how to use that.