-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.

  • Elaborate your question in detail –  Jul 29 '15 at 12:49
  • @Android Weblineindia I'd like to make notification when application is on background after 1hour. So I made countdown. But don't know how to make notification. – network Jul 29 '15 at 12:52
  • Duplicate. Please refer to the following question http://stackoverflow.com/questions/13902115/how-to-create-a-notification-with-notificationcompat-builder – moud Jul 29 '15 at 12:54
  • i have edited my answer please check –  Jul 29 '15 at 13:28

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);