Note that there are some explanatory texts on larger screens.

plurals
  1. POGet Thread sleep duration from App Preferences
    primarykey
    data
    text
    <p>I am trying to allow users of my app to change the length of the splash screen. I created an EditTextPreference in my preferences.xml and gave it a default value of 5. The key is "duration". I figured that I could use SharedPreferences and use the getLong method to get the value of the field, and then use it as the parameter for the Thread's sleep method.</p> <p>Here is my code:</p> <pre><code>SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); long dur = prefs.getLong("duration", 5); final long duration = dur*1000; //convert from seconds to milliseconds Thread timer = new Thread() { public void run() { try{ sleep(duration); } catch (InterruptedException e) { e.printStackTrace(); } finally { Intent openMenu = new Intent("com.heh.blah.MENU"); startActivity(openMenu); } } }; timer.start(); </code></pre> <p>This code works perfectly fine as long as the preference isn't changed. However, if I go into the preferences and change the Duration preference (even if I don't change it and just hit "ok" with the default value of 5 in the box OR hit cancel) and close the app, the next time it opens, the screen goes all white for a few seconds, then all black, and then it crashes and I get the "Unfortunately, App has stopped." popup box. Clearing app data allows the app to start up normally again (but with a 5 second splash screen).</p> <p>UPDATE: Just opening the preferences EVEN WITHOUT CHANGING CLICKING ON OR CHANGING ANYTHING causes it to crash during the next start up.</p> <p>Any help with this issue would be much appreciated!!!</p> <p>Thanks, Max</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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