0

I am working on a project in which I want start a service at exactly 11:00am without user interaction. Is it possible?

    Calendar c = Calendar.getInstance();
    System.out.println("Current time => "+c.getTime());

    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String formattedDate = df.format(c.getTime());
    // formattedDate have current date/time
    Toast.makeText(this, formattedDate, Toast.LENGTH_SHORT).show();


    // Now we display formattedDate value in TextView
    TextView txtView = new TextView(this);
    txtView.setText("Current Date and Time : "+formattedDate);
    txtView.setGravity(Gravity.CENTER);
    txtView.setTextSize(20);
    setContentView(txtView);
}

I have tried this code to fetch the real time but it's not for API's less than 25.

BSMP
  • 4,596
  • 8
  • 33
  • 44
  • 1
    use alarm manager – Divyesh Patel May 12 '17 at 12:45
  • refer http://stackoverflow.com/questions/16870781/fire-notification-at-every-24-hours-and-at-exact-time-of-8-am – sasikumar May 12 '17 at 12:45
  • Use alarm manager with broadcaset receiver and fire service form there – Vikas Rathod May 12 '17 at 12:49
  • Some good reading on this: https://www.bignerdranch.com/blog/choosing-the-right-background-scheduler-in-android/ – gitter May 12 '17 at 13:30
  • Welcome to Stack Overflow. I just fixed some minor grammar errors and fixed the formatting of your first line of code. Just keep in mind that "I" as a word should always be capitalized. Also note that you don't need to include "please help" and similar phrases; it's assumed you need help and a solution. – BSMP May 12 '17 at 22:28

0 Answers0