Enable / Disable Toast from General Settings?

Is there a way to globally enable and disable toast notifications using the checkbox in the general settings?

PreferenceManager.setDefaultValues(this, R.xml.preferences, false); boolean showToast = myPrefs.getBoolean("showToast", true); 

I thought maybe to make a class:

 boolean showToast(){ //code } 

BUT thought SO could have a global solution?

Should I use a different type of notification system?

Any thoughts?

+6
source share
5 answers

You might consider adding Toast to create your own class that is smart enough to read user preferences before showing the toast.

Then reformat your code to replace Toast with SmartToast.

SmartToast.makeText(this, "message", Toast.LENGTH_SHORT).show();

Add SmartToast.makeText () to return an instance of SmartToast and override show () as follows:

 @Override public void show() { if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("showToast", true)) { super.show(); } } 
+1
source

Why don't you put the value of the flag in the general settings, and then use it as a flag if the (flag) {show toast}, for example, is not the same?

0
source

You can disable or activate notifications only for toasts, for example, how to do it, but not globally for all applications

0
source

You can try creating an enumeration with one element -

 public enum YourSingleton { INSTANCE; // element in this enum public static void makeToast(Context context, String msg) { Toast toast = Toast.makeText(context, msg, Toast.LENGTH_LONG); toast.show(); } 

} And then call -

  YourSingleton .makeToast(this, "Toast Message"); 

If you want to turn it on or off, you can just do it in the makeToast () method.

0
source

use onSharedPreferenceChangeListener.

0
source

All Articles