I am developing App-Locker app and i have background service which is running. But i want the exact solution to trigger one function inside that background service when any application is launch or open in mobile. I am using the below service which runs continuously.
public class NotificationService extends Service {
public NotificationService() {
}
@Override
public IBinder onBind(Intent intent)
{
Log.e("Noftication serveric ", " Onbinddddd");
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
super.onStartCommand(intent, flags, startId);
return START_STICKY;
}
@Override
public void onDestroy()
{
super.onDestroy();
//Starting Broadcast on destroy method, where this service is called again to run
Intent restartService = new Intent("RestartService");
sendBroadcast(restartService);
}
public void Trigger_Me_If_Any_App_Launch()
{
//This function should be called if any app launch
}
}