0

I have a list of apps that I would like to run in a specific sequence and then a "main app" where the user would click a start button and then it would launch an app and once the time is up, it would launch the second app and then repeat for the third and fourth apps. All the apps have an auto time out already and once the time is reached, the application ends and you are taken back to the "Main App". there is a time per app that is set, but when each app launches, the user is brought to a screen where they click to begin in each app. Furthermore, the timing is internal to each application.I was thinking of something like:

User is in "Main App":

  1. User clicks "Start" button in "Main APP"
  2. App 1 is launched and time begins
  3. App 1 time ends and then App 2 is launched
  4. App 2 time ends and then App 3 is launched
  5. App 3 time ends and then App 4 is launched
  6. App 4 time ends and then it returns to the "Main App"

Is there a way to programmatically do this in Android?

cjstittles
  • 61
  • 5
  • yup you can launch each of them with timer. better to set timer in foreground service. – Elias Fazel Mar 14 '17 at 21:47
  • Thank you for your response! However, I only want the next app to launch after the activity in the prior app is completed (there is a time per app that is set, but when the app launches, the user is brought to a screen where they click to begin in each app) – cjstittles Mar 14 '17 at 22:09

1 Answers1

0

By Apps you mean Activities/Screens? If I understood correctly, you should use this to switch between Activities/Screens (this example delays launch of activity for 5 seconds.):

new Handler().postDelayed(new Runnable() {
    @Override
        public void run() {
        Intent i=new Intent(getApplicationContext(),SecondScreen.class);
        startActivity(i);
    }
}, 5000);

If I am right, you should be able to do some work in current Activity after you called this code. In case user did all you wanted from him, simply call this:

Intent i = new Intent(getApplicationContext(), SecondScreen.class);
StartActivity(i);

Link to the original answer about delaying activity call

if you are about to switch between applications, try following code:

new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        PackageManager manager = context.getPackageManager();
        try {
            Intent i = manager.getLaunchIntentForPackage(com.google.android.yourApp);
            if (i == null) {
                //throw new PackageManager.NameNotFoundException();
            }
            i.addCategory(Intent.CATEGORY_LAUNCHER);
            context.startActivity(i);
        }
    }
}, 5000);

Link to the original answer about calling new application

Community
  • 1
  • 1
  • Thank you for the reply! By apps, I do mean differing applications. We are doing subject testing with a variety of applications that we have developed in house, so we need them to run in a sequence. Any ideas? – cjstittles Mar 15 '17 at 20:48
  • I edited the answer for you, check it out! Try if it works, and give me some feedback! – Фред Генкин Mar 16 '17 at 22:15