CopyPastor

Detecting plagiarism made easy.

Score: 2; Reported for: String similarity, Exact paragraph match Open both answers

Possible Plagiarism

Plagiarized on 2020-08-29
by Taha Gorme

Original Post

Original - Posted on 2014-06-16
by Tanasis



            
Present in both answers; Present only in the new answer; Present only in the old answer;

- If you want an external app use: [Autostart and StaY!][1]

[1]: https://play.google.com/store/apps/details?id=com.atasoglou.autostartandstay
- If you want to do this programmatically you can use a service that polls every "x" milliseconds to see if your app is in the foreground. If it is not, it will start/bring your app in the foreground. Do it like this:
public class PersistService extends Service { private static final int INTERVAL = 3000; // poll every 3 secs private static final string YOUR_APP_PACKAGE_NAME = "YOUR_APP_PACKAGE_NAME"; private static boolean stopTask; private PowerManager.WakeLock mWakeLock; @Override public void onCreate() { super.onCreate(); stopTask = false; // Optional: Screen Always On Mode! // Screen will never switch off this way mWakeLock = null; if (settings.pmode_scrn_on){ PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "a_tag"); mWakeLock.acquire(); } // Start your (polling) task TimerTask task = new TimerTask() { @Override public void run() { // If you wish to stop the task/polling if (stopTask){ this.cancel(); } // The first in the list of RunningTasks is always the foreground task. RunningTaskInfo foregroundTaskInfo = activityManager.getRunningTasks(1).get(0); String foregroundTaskPackageName = foregroundTaskInfo .topActivity.getPackageName(); // Check foreground app: If it is not in the foreground... bring it! if (!foregroundTaskPackageName.equals(YOUR_APP_PACKAGE_NAME)){ Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(YOUR_APP_PACKAGE_NAME); startActivity(LaunchIntent); } } }; Timer timer = new Timer(); timer.scheduleAtFixedRate(task, 0, INTERVAL); }
@Override public void onDestroy(){ stopTask = true; if (mWakeLock != null) mWakeLock.release(); super.onDestroy(); } }
The above code has also the "option" to force the Screen to stay always on! Of course you will need the following permissions:
<uses-permission android:name="android.permission.GET_TASKS" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
and do not also forget to register your service:
<service android:name="YOURPACAKGE.PersistService" android:enabled="true"/>
- If you want an external app use: [Autostart and StaY!][1]

[1]: https://play.google.com/store/apps/details?id=com.atasoglou.autostartandstay
- If you want to do this programmatically you can use a service that polls every "x" milliseconds to see if your app is in the foreground. If it is not, it will start/bring your app in the foreground. Do it like this:
public class PersistService extends Service { private static final int INTERVAL = 3000; // poll every 3 secs private static final string YOUR_APP_PACKAGE_NAME = "YOUR_APP_PACKAGE_NAME"; private static boolean stopTask; private PowerManager.WakeLock mWakeLock; @Override public void onCreate() { super.onCreate(); stopTask = false; // Optional: Screen Always On Mode! // Screen will never switch off this way mWakeLock = null; if (settings.pmode_scrn_on){ PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "a_tag"); mWakeLock.acquire(); } // Start your (polling) task TimerTask task = new TimerTask() { @Override public void run() { // If you wish to stop the task/polling if (stopTask){ this.cancel(); } // The first in the list of RunningTasks is always the foreground task. RunningTaskInfo foregroundTaskInfo = activityManager.getRunningTasks(1).get(0); String foregroundTaskPackageName = foregroundTaskInfo .topActivity.getPackageName(); // Check foreground app: If it is not in the foreground... bring it! if (!foregroundTaskPackageName.equals(YOUR_APP_PACKAGE_NAME)){ Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(YOUR_APP_PACKAGE_NAME); startActivity(LaunchIntent); } } }; Timer timer = new Timer(); timer.scheduleAtFixedRate(task, 0, INTERVAL); }
@Override public void onDestroy(){ stopTask = true; if (mWakeLock != null) mWakeLock.release(); super.onDestroy(); } }
The above code has also the "option" to force the Screen to stay always on! Of course you will need the following permissions:
<uses-permission android:name="android.permission.GET_TASKS" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
and do not also forget to register your service:
<service android:name="YOURPACAKGE.PersistService" android:enabled="true"/>

        
Present in both answers; Present only in the new answer; Present only in the old answer;