-1

I have an dialog which I wanted to show the dialog after every hour in android, its like Scheduled time, is this possible to do?

 Dialog dialog = new Dialog(MainActivity.this);
            dialog.setContentView(R.layout.collect_points);
            dialog.findViewById(R.id.collect_point_everyday).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dialog.dismiss();
                }
            });
            dialog.show();
a_local_nobody
  • 7,947
  • 5
  • 29
  • 51
Aisha Kumari
  • 193
  • 2
  • 9
  • https://stackoverflow.com/a/11434143/11647620 – Usama Altaf Jan 21 '22 at 07:53
  • Use [`AlarmManager`](https://developer.android.com/reference/android/app/AlarmManager) Its the right way to do it. Use [`setExactAndAllowWhileIdle`](https://developer.android.com/reference/android/app/AlarmManager#setExactAndAllowWhileIdle(int,%20long,%20android.app.PendingIntent)) to set the Alarm . – ADM Jan 21 '22 at 07:56
  • You need to handle few things though. 1. If you need to show dialog even if App is closed you gotta open an Activity . If not and you want to postponed it further till next Hour the you can save a value in `SharedPreference` and whenever your Activity gets open you check the value in `SharedPreference` and show the Dialog if needed. If you do not want to postponed it then do nothing . 2. On every Alarm call you need to set Subsequent Alarm for next Hour. – ADM Jan 21 '22 at 07:57

1 Answers1

0

You need to use service for this task. you can look into this answer thread.

Awais Latif
  • 101
  • 1
  • 7