-1

I made some application and I'd like to add notification to user when application going on a background after 1hours.

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

       setContentView(R.layout.main);

   }
   @Override
   public void onWindowFocusChanged(boolean hasFocus) {
        if (!hasFocus) {
            new CountDownTimer(1000, 1) {
                 public void onTick(long millisUntilFinished) {

                  }

                 public void onFinish() {
                  //Timer is ended

                 }

                 }.start();

                }
              super.onWindowFocusChanged(hasFocus);
            }

This is my code but I don't know how to make notification..Please help me with full codes.

1 Answers1

0

You don't need to use ConuntDownTimer for that.

You can use alarm manager for it. now you can ask the alarm manager class to send a message on the desired time which your application will receive.

You will have to program your activity in a way that it responds to this message and displays a notification to the user.

you can refer following link

http://android-er.blogspot.in/2010/10/simple-example-of-alarm-service-using.html

and for after 1 hour you can add 3600 in calender.add() method

for example

calendar.add(Calendar.SECOND, 3600);
Mobile Team ADR-Flutter
  • 12,062
  • 2
  • 29
  • 49