Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bring application back to front

Tags:

android

My application is a timer with alarm type app. When the timer expires i would like to bring the app's main activity back into view, if the user has navigated away, but the app is still running.

I show where i would like to place the necessary code:

   public class MyCount extends CountDownTimer {
        public MyCount(long millisInFuture, long countDownInterval) {
          super(millisInFuture, countDownInterval);
        }

        public void onFinish() {

         /** code here to bring the app back to the front / top of stack, in its current state */


         timeDisplay.setText("Expired.!");
         ReminderFlashingScreen.setVisibility(View.GONE);
         statustab.setBackgroundResource(R.drawable.redtab);
         seeker.setProgress(0);
         reset.setBackgroundResource(R.drawable.resetbtnoff);
         playExpiredAlarm(); 
         alarmAnimation.start();
         flasher.setVisibility(View.VISIBLE);
         StopAlarmButtonAnimation.start();
         StopAlarmButton.setVisibility(View.VISIBLE);
         expired = true;
        }

        public void onTick(long millisUntilFinished) {
            remindertimepref = prefs.getString("reminderTime", "<unset>");
            remindtime = Integer.parseInt(remindertimepref.trim());
            timeDisplay.setText(formatTime(millisUntilFinished));
            seeker.setProgress((int) (millisUntilFinished / 1000 / 60 ) + 1);
            if (used == true){
                reminder_time = ((int) (millisUntilFinished / 1000));
                if (reminder_time == remindtime){
                    reminderalarm();
                    used = false;
                    }
                }

          }
    }
like image 399
11Monkeys Avatar asked Dec 11 '10 11:12

11Monkeys


1 Answers

For me it was this:

Intent intent = new Intent(Application.getContext(), AbstractFragmentActivity.instance.getClass());
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
intent.addFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Application.getContext().startActivity(intent);
like image 168
Kevin Parker Avatar answered Oct 23 '22 02:10

Kevin Parker