Note that there are some explanatory texts on larger screens.

plurals
  1. POI would like to update my app UI, but ONLY if my app is in the foreground
    primarykey
    data
    text
    <p>I have an app that is very simple - it turns bluetooth on and off according to whether it's plugged in.</p> <p>The app right now is also very simple in terms of UI - there is 1 button on there, that allows you to turn bluetooth on and off if you want.</p> <p>I actually have this working, and have figured out how to update the button, but, I would like to update my UI only if the app is in the foreground - so, if I plug in my phone, and i'm NOT in my app, I <em>don't</em> want my app to pop up and update the UI - I only want the UI to change if the app was open when I plugged in the phone.</p> <p>I've tried the following code, and it does find the app in the running apps list, but it opens the app no matter what - i.e., it'll open the app and update my UI whether it was open before or not.</p> <pre><code> ActivityManager activityManager = (ActivityManager) context.getSystemService( Context.ACTIVITY_SERVICE ); List&lt;RunningAppProcessInfo&gt; appProcesses = activityManager.getRunningAppProcesses(); for(RunningAppProcessInfo appProcess : appProcesses){ if(appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND){ Log.i("Foreground App", appProcess.processName); if(appProcess.processName.equals("vermel.BluetoothOn")) { //update UI } } } </code></pre> <p>What am I doing wrong? Please bear in mind, I'm a fresh newbie in both Java and Android, and would highly appreciate details explanation, as opposed to a link to the android development documentation ;)</p> <p>Thanks for reading!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload