Search code examples
androideventsbackground-service

Android Background Service triggers event in main app


I'm trying to create an application that will blacklist certain applications (based on user input) and will block these applications from launching by bringing the main (or some other part of my app) to the foreground when the blacklisted apps are detected in the foreground.

This will be similar to Smart App Protector, but with additional trigger conditions.

I have the service detecting the apps fine, but I'm having trouble getting the main activity to come to the front.

Any ideas? Thanks in advance.


Solution

  • Use this when you detect the blacklisted applicaton:

    Intent startupIntent = new Intent(context, ActivityToLaunch.class);
    startupIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(startupIntent);