Situation:
In order to bring your app to the foreground, you must call startActivity() from another context (either a Service or a BroadcastReceiver). Just calling startActivity() from within an Activity won't bring your app to the foreground.
You don't need the ACTION and CATEGORY in your Intent, but you do need to set Intent.FLAG_ACTIVITY_NEW_TASK.
Just establish a Service, doing whatever you want it to in the background. Or even better: Do something in the background, listen to it with a listener, bind a Service as soon as the event you waited for occurs (timer etc). Now that you are in the Service, you just call the Activity that should be on foreground like you would from anywhere else:
Intent i = new Intent(MyService.this, MyActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MyService.this.startActivity(i);
David Wasser answer helped to solve my problem.
My Activity is running in a foreground Service so I had to call startActivity() method from that Service context.
Intent intent = new Intent(context, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mServiceContext.startActivity(intent);
The best way to do it I think is via an IntentService. It works this way too, and it's probably the easiest way. So the sequence is: register a receiver in the Activity (in onCreate) to listen for the event you want, then when the receiver gets the event, it launches an IntentService the standard way and this in turn starts the Activity.
This way it will put the app in front of other apps, both active and hidden ones. (But this should be used with caution. Normally the user won't like another app popping up in front of the one he's working with, except if there's a very good reason for it.)
On my KitKat device (4.4.x), I tested it and I can bring the app to front by calling startActivity from a receiver in the Activity only if there is no other app open, that is my app is hidden under the home screen. Then it will come on top. If another app is open, even if it's also hidden (but in front of my app; I actually didn't test to see what happens if both apps are hidden and mine is in front, but that's not very important), then it won't come on top if started from within the same Activity. So to make it always pop up you need to use an IntentService (or another way but this is as far as I know the simplest one).
To Resume application from background programmatically will
Make your activity FOREGROUND, User's current activity in BACKGROUND. User's work is GONE
This is not right behavior from user perspective. Additionally, if we resume activity programmatically, the activity lifecycle will be broken. The activity states will be lost.
Alternative :
You can provide NOTIFICATION when your timer, task (anything) is complete in background. If user is interested in checking your activity then he/she can check from NOTIFICATION without interrupting current work
If your activities are on different tasks, you can use this to bring the activity's task to foreground:
ActivityManager activityManager = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
activityManager.moveTaskToFront(getTaskId(), ActivityManager.MOVE_TASK_NO_USER_ACTION);
You would need android.permission.REORDER_TASKS in order to do so. It works even in Android M, however getting an intent from a service works better in some cases.