How can I make an app reopen when closed on an Android device?

82 Views Asked by At

I have a .bat file. This file contains code that reopens an application when it is closed. So how can I run this on Android? I want it to constantly check in the background and run it if the application is closed. I only have the apk file of the application. I don't have access to the source code.

I tried this code in an application on Windows. It checks every 10 seconds and turns on the device if it is off. How can I do this on an android device?

Does it make more sense to make a mobile application and have it checked? Or is there a way to make this file extension work consistently on Android? (systemd, init.d)..

1

There are 1 best solutions below

1
 Zain On BEST ANSWER

On Android devices, apps generally close when you navigate away from them or use the task manager to close them. However, you can't force an app to automatically reopen after it has been closed by the user. Android follows a user-centric approach, prioritizing user control and privacy.

However, you can achieve a similar effect using services, notifications, or background processes. Here are some methods you can explore:

1. Foreground Service:

  • Create a foreground service within your app. A foreground service is a type of service that shows a persistent notification to the user.
  • This notification can act as a quick way for the user to return to the app. When the user taps the notification, it can open the app.
  1. AlarmManager:

    • You can use Android's AlarmManager to schedule your app to open at specific intervals or times.
    • Note that abusing this feature can be considered intrusive, and users may find it annoying.
  2. Broadcast Receiver:

    • Register a BroadcastReceiver to listen for system events. For example, you can listen for the device booting up or other system events.
    • When the desired event occurs, launch your app.

Remember to respect user preferences and privacy. Forcing an app to reopen can be perceived as intrusive, and users might find it undesirable. Always ensure that your app follows the best practices and guidelines set by the Android platform. Also, be mindful of the impact on battery life and overall user experience.

Additionally, Android app behavior may vary across different versions and manufacturers, so test your implementation on various devices to ensure compatibility.