0

I want to initiate a timer service when activity C is called now from activity C i can go to activity D and E but when the timer stopped then I want to redirect on activity A (Home Page), it doesn't matter which activity open after timer it may be C, D or E . i also want to show the left time in C, D, E activities

This kind of timer i want

// Timer to maintain session

        new CountDownTimer(420 * 1000 + 1000, 1000) {
            public void onTick(long millisUntilFinished) {
                int seconds = (int) (millisUntilFinished / 1000);
                int hours = seconds / (60 * 60);
                int tempMint = (seconds - (hours * 60 * 60));
                int minutes = tempMint / 60;
                seconds = tempMint - (minutes * 60);
                textView.setText(String.format("%02d", minutes) + ":" + String.format("%02d", seconds));
            }
            public void onFinish() {
                textView.setText("Completed");
            }
        }.start();  
Micer
  • 8,731
  • 3
  • 79
  • 73
  • I don't see any relation between your question title and question body. – Vladyslav Matviienko Mar 30 '18 at 05:49
  • i basically want to call my home page activity with a alert box when given time period will expire (Time calculation done by timer service), it does not matter which activity is the current activity when time session will expire if session expired the execution should redirected to home page with a alert box. – user9106826 Apr 08 '18 at 08:45
  • 1
    Does this answer your question? [android start activity from service](https://stackoverflow.com/questions/3606596/android-start-activity-from-service) – Ryan M Oct 25 '21 at 23:02

2 Answers2

0

You can open the activity in onFinish() with creating new Intent:

Intent intent = new Intent(textView.getContext(), ActivityA.class);                      
startActivity(intent);

To initiate the service, you can call:

startService(new Intent(this, YourServiceClass.class));
Micer
  • 8,731
  • 3
  • 79
  • 73
0

To start a service to perform a one-time operation by passing an Intent to startService().

intent dialogIntent = new Intent(this, MyActivity.class);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(dialogIntent);

try this.

Android Geek
  • 8,956
  • 2
  • 21
  • 35