ANR in com.example.package, Input dispatching timed out

Viewed 170

when I open my app and touch the screen to pick time using TimePicker I get an error

Note: in my MainActivity, I am loading some audio files in the Recyclerview from firebase. the loading of these songs takes nearly 5 seconds. this is also a problem for me

Note: this error happens only if I scroll Timepicker before loading all audio files.

error

01-01 08:16:35.899 50-65/system_process E/ActivityManager: ANR in com.example.alarm (com.example.alarm/.MainActivity)
    PID: 434
    Reason: Input dispatching timed out (Waiting because the touched window has not finished processing the input events that were previously delivered to it.)
    Load: 0.0 / 0.0 / 0.0
    CPU usage from 0ms to 10699ms later:
      0% 11/debuggerd: 0% user + 0% kernel
    0% TOTAL: 0% user + 0% kernel
    CPU usage from 10076ms to 10584ms later:
    0% TOTAL: 0% user + 0% kernel

MainActivity.java` file

public class MainActivity extends AppCompatActivity {


    TimePicker timepickerwatch;
    TextView cancelalarm,AlarmSetterbtn;
    FirebaseStorage storage;
    RecyclerView recyclerview;
    Button upload_your_own;

    int almhour,almminute;

    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        upload_your_own = findViewById(R.id.upload_your_own);
        timepickerwatch = findViewById(R.id.timepickerwatch);
        AlarmSetterbtn = findViewById(R.id.AlarmSetterbtn);
        cancelalarm = findViewById(R.id.cancelalarm);
        recyclerview = findViewById(R.id.recyclerview);
        storage = FirebaseStorage.getInstance();


        Calendar calendar = Calendar.getInstance();

        ArrayList<RingtoneModel> list = new ArrayList<>();
        Ringtone_Adpter adpter = new Ringtone_Adpter(list,MainActivity.this);

         new Methods().Firebase_RING_download(list,adpter); //this is a method in my Method class to Download and set audios in their model class

    recyclerView.setAdapter(adpter);
    recyclerView.setLayoutManager(new LinearLayoutManager(context));

        timepickerwatch.setOnTimeChangedListener((view, hourOfDay, minute) -> {
            almhour = hourOfDay;
            almminute = minute;

            calendar.set(Calendar.HOUR_OF_DAY,almhour);
            calendar.set(Calendar.MINUTE,almminute);
            calendar.set(Calendar.SECOND,0);
        });

        AlarmSetterbtn.setOnClickListener(v -> {AlarmStart(calendar);
            Toast.makeText(this, "Alarm Set Successfully", Toast.LENGTH_SHORT).show();
            Intent alarmchanged = new Intent("android.intent.action.ALARM_CHANGED");
            alarmchanged.putExtra("alarmset","enabled");
            MainActivity.this.sendBroadcast(alarmchanged);
        });

        cancelalarm.setOnClickListener(v -> Alarmclose());
    }

to handle this I also tried

//created a new class which extends Thred 
class NewThread extends Thread{
    RecyclerView recyclerView;
    ArrayList<RingtoneModel> list;
    Ringtone_Adpter adpter;
    Context context;

    public NewThread(RecyclerView recyclerView, ArrayList<RingtoneModel> list, Ringtone_Adpter adpter,Context context) {
        this.recyclerView = recyclerView;
        this.list = list;
        this.adpter = adpter;
        this.context = context;
    }

    @Override
    public void run() {
        super.run();
        new Methods().Firebase_RING_download(list,adpter);
        recyclerView.setAdapter(adpter);
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        Log.d("tag","New Thread run working");
    }
}

and called this in Mainactivity class

NewThread newThread = new NewThread(recyclerview,list,adpter,MainActivity.this);
        newThread.start();

what I am doing wrong

0 Answers
Related