I want to design an activity in which I have button with a title "Do not show the screen again in future", on pressing which the splash screen is skipped no matter no how many times user opens the application.
I tried using android shared Preferences (seeing answer for other questions) but I am not getting the desired output. I have given below the code I have used. Please let me know in what way the code must be corrected. If there any other means, I am happy to learn that.
Thanks in Advance.
private class MyThread extends Thread
{
public boolean bRun = true;
@Override
public void run()
{
try
{
sleep(10000);
if (bRun)
{
startActivity(new Intent(getApplicationContext(), PnbActivity.class));
}
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
public class Preference {
private SharedPreferences sharedPreferences;
private SharedPreferences.Editor editor;
public Preference(Context context) {
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
}
public void writePreference(String key, Object value) {
if(value instanceof Boolean) {
editor = sharedPreferences.edit();
editor.putBoolean(key, (Boolean) value);
editor.commit();
}
}
public Object readPreference(String key , Object defValue) {
if(defValue instanceof Boolean)
return sharedPreferences.getBoolean(key, (Boolean) defValue);
else
return null;
}
public Boolean getDisableSplash() {
return (Boolean) readPreference("disable", false);
}
public void disableSplash(Boolean value) {
Object valve = null;
writePreference("disable", valve);
}
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_note);
Preference preference = new Preference(Note.this);
Boolean result = preference.getDisableSplash();
if(!result) {
// dissable you splash activity here and move to next one
}
thread = new MyThread();
thread.start();}}
public void skipAct(View v){
Preference preference = new Preference(Note.this);
preference.disableSplash(true);
Intent i = new Intent(Note.this, PnbActivity.class);
startActivity(i);
}