[Android Apps and Games] daxgirl:
Handling all keys necessary for killing processes in your app

So jokes aside, lets say you have more then one app you need to kill when the preference changes and more than one key for each app. And I am not talking about just one fragment, but ALL fragments you use in the ENTIRE APP:

What we can do is this:

1. In HandlePreferenceFragments class go to the end of the class and add those 2 methods before the closing bracket:

//You can gather here all relevant keys for process killing from your entire app!!! Not only certain fragment!!!
[COLOR="Blue"][B] private void handleKeysToKillProcess(String key){
[COLOR="Green"] String[] [COLOR="DarkRed"]keysForContacts[/COLOR] = {"dialer_background_color", "main_digit_color", "main_letter_color"};
String[] [COLOR="Teal"]keysForInCallUI[/COLOR] = {"incall_dialer_bg_color", "incall_dialer_bg_type", "incall_dialer_main_digit_color", "incallDialer_main_letter_color", "toggle_call_recording"};
String[] [COLOR="DarkSlateGray"]keysForSystemUI[/COLOR] = {"toggle_color_overlay", "brightness_panel_pg_transparency", "statusbar_clock_position"};[/COLOR]
[COLOR="DarkOrchid"]String[][] allArrays = {[COLOR="DarkRed"]keysForContacts[/COLOR], [COLOR="Teal"]keysForInCallUI[/COLOR], [COLOR="DarkSlateGray"]keysForSystemUI[/COLOR]}; //the order of objects matters! ([COLOR="DarkRed"]0[/COLOR],[COLOR="Teal"]1[/COLOR],[COLOR="DarkSlateGray"]2[/COLOR])[/COLOR]
for (int objPos = 0; objPos<allArrays.length; objPos++){
for(int keyPos=0; keyPos<allArrays[objPos].length; keyPos++){
if(key.equals(allArrays[objPos][keyPos])){
switch(objPos){
[COLOR="DarkRed"]case 0:[/COLOR] //array keysForContacts
killProcess("com.android.contacts");
break;
[COLOR="Teal"]case 1:[/COLOR] //array keysForInCallUI
killProcess("com.android.incallui");
break;
[COLOR="DarkSlateGray"]case 2:[/COLOR] //array keysForSystemUI
killProcess("com.android.systemui");
/**
* Or since you're using systemui kill here
* You can call a method appRebootRequired("com.android.systemui") for visible reboot*/
break;

}
}
}
}
}

private void killProcess(String pckgName){
Command c = new Command(0, "pkill " + pckgName);
try {
RootTools.getShell(true).add(c);
} catch (IOException e) {
e.printStackTrace();
} catch (TimeoutException e) {
e.printStackTrace();
} catch (RootDeniedException e) {
e.printStackTrace();
}
}
[/B][/COLOR]
} <-- Closing bracket for the entire class

2. Gather all your keys that need killing some app and sort them inside relevant arrays (in green). It doesn't matter in what order you create String[] objects for all your keys (in green), but it does matter in what order you put them into an object array of string arrays (purple). See how colors corolate to how we use them in switch/case!

3. Fine method called update private void updateDatabase(String key, Object o, SharedPreferences sp)

4. Add call for our new method like this:

private void updateDatabase(String key, Object o, SharedPreferences sp) {
boolean isEnabled;
int dbInt;
String value = "";

if (o instanceof SwitchPreference || o instanceof CheckBoxPreference) {
isEnabled = sp.getBoolean(key, true);
dbInt = (isEnabled) ? 1 : 0;
Settings.System.putInt(cr, key, dbInt);
} else if (o instanceof MyEditTextPreference || o instanceof MyListPreference || o instanceof IntentDialogPreference) {
value = sp.getString(key, "");
Settings.System.putString(cr, key, value);
} else if (o instanceof ColorPickerPreference) {
dbInt = sp.getInt(key, Color.WHITE);
Settings.System.putInt(cr, key, dbInt);
} else if (o instanceof SeekBarPreference) {
dbInt = sp.getInt(key, 0);
Settings.System.putInt(cr, key, dbInt);
}

[COLOR="Blue"][B]handleKeysToKillProcess(key);[/B][/COLOR]
}

This should take care of all your keys that need app killing.

4. Pay attention to the comment inside the case 2 (for killing systemui). Since killing systemui is a visibple process, you might consider using method appRebootRequired(String pckgName) for this one.

I haven't tested this, as I also haven't tested the previous method I published (our app is not operational), but it has sound logic to it, don't worry. Tis should compile and run no problem!!! So if anyone ( [MENTION=1167171]rompnit[/MENTION] ) wants to try this method, be my guest!