Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>"FIRST only one checkbox should be checked ."</p> <p>Not sure how to make this a short and easy answer, but hang with me, this works.</p> <p>Create a preference activity that you call from your activity.</p> <p>Use something like this in your onOptionSelected:</p> <pre><code> case R.id.prefs: Intent p = new Intent(MainActivity.this, Prefs.class); startActivity(p); break; </code></pre> <p>This is the Prefs.class</p> <pre><code>public class Prefs extends PreferenceActivity { CheckBoxPreference splash; CheckBoxPreference splash_music; CheckBoxPreference no_splash_music; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.prefs); splash = (CheckBoxPreference) findPreference("splash"); splash_music = (CheckBoxPreference) findPreference("splash_music"); no_splash_music = (CheckBoxPreference) findPreference("without_splash_screen"); splash.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { // TODO Auto-generated method stub splash.setChecked(true); splash_music.setChecked(false); no_splash_music.setChecked(false); return true; } }); splash_music .setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { // TODO Auto-generated method stub splash.setChecked(false); splash_music.setChecked(true); no_splash_music.setChecked(false); return true; } }); no_splash_music .setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { // TODO Auto-generated method stub splash.setChecked(false); splash_music.setChecked(false); no_splash_music.setChecked(true); return true; } }); } } </code></pre> <p>And don't forget to add it to the Manifest:</p> <pre><code> &lt;activity android:name="com.lordmarty.testforlools.Prefs" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="com.lordmarty.testforlools.PREFS" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; </code></pre> <p>The prefs.xml file is the same as the one you posted.</p> <p>Let me know if you get any errors. I've tested it, and it works fine here.</p> <p>"SECOND"</p> <p>Not sure why you have to click twice. But it might be caused by the splash not finishing, just calling a new intent. Try this where ever you start your mainclass from the splash:</p> <pre><code> finally{ Intent intent = new Intent(Splash.this, MainActivity.class); startActivity(intent); finish(); } </code></pre> <p>Now, I've looked over your project and found out why it where so buggy.</p> <p>Main reason:</p> <pre><code> if (music == true) ourSong.start(); Thread timer = new Thread(){ </code></pre> <p>Here you are missing a brackets for the if statement, causing the thread to run everytime. Therefore you have two MainActivities running at the same time.</p> <p>Other notes: You use "if"'s for all the values. I suggest you use "else if".</p> <p>And I did a small cleanup.</p> <p>Here u go. Enjoy:</p> <p><a href="https://www.dropbox.com/s/tu14tptvd9kxtm8/Splash.java" rel="nofollow">Link to Splash.java</a></p> <p>You can solve the last problem in many ways. One of them being this:</p> <pre><code>// add this below the other if else if statements in the splass.java else if(without_splash_screen == false &amp;&amp; splash == false &amp;&amp; music == false){ //put whatever you want to happen if none of them are checked. This is just an example. setContentView(R.layout.splash); setContentView(R.layout.splash); Thread timer = new Thread() { public void run() { try { sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } finally { Intent intent = new Intent(Splash.this, MainActivity.class); startActivity(intent); finish(); } } }; timer.start(); </code></pre>
 

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