snipt

Ctrl+h for KB shortcuts

Java

Show a popup notification

            Toast.makeText(this, "Hello world",
                    Toast.LENGTH_SHORT).show();
https://snippets.siftie.com/embed/171fad585210d03ea6ce0b317205c17d/
/raw/171fad585210d03ea6ce0b317205c17d/
171fad585210d03ea6ce0b317205c17d
java
Java
3
2019-03-15T09:35:18
True
False
False
/api/public/snipt/12341/
show-a-popup-notification
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a> <span class="n">Toast</span><span class="o">.</span><span class="na">makeText</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="s">&quot;Hello world&quot;</span><span class="o">,</span> </span><span id="L-2"><a name="L-2"></a> <span class="n">Toast</span><span class="o">.</span><span class="na">LENGTH_SHORT</span><span class="o">).</span><span class="na">show</span><span class="o">();</span> </span></pre></div> </td></tr></table>
android

Java

Init reading of prefs

1
2
3
4
//Also add to beginning of class
//SharedPrefences prefs=null;
prefs=PreferenceManager.getDefaultSharedPreferences(this);
prefs.registerOnSharedPreferenceChangeListener(prefListener);
https://snippets.siftie.com/embed/e5e335a59d109dcb3289bbe6ae2601e6/
/raw/e5e335a59d109dcb3289bbe6ae2601e6/
e5e335a59d109dcb3289bbe6ae2601e6
java
Java
5
2017-01-01T10:54:36
True
False
False
/api/public/snipt/11088/
init-reading-of-prefs
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1">//Also add to beginning of class</span> </span><span id="L-2"><a name="L-2"></a><span class="c1">//SharedPrefences prefs=null;</span> </span><span id="L-3"><a name="L-3"></a><span class="n">prefs</span><span class="o">=</span><span class="n">PreferenceManager</span><span class="o">.</span><span class="na">getDefaultSharedPreferences</span><span class="o">(</span><span class="k">this</span><span class="o">);</span> </span><span id="L-4"><a name="L-4"></a><span class="n">prefs</span><span class="o">.</span><span class="na">registerOnSharedPreferenceChangeListener</span><span class="o">(</span><span class="n">prefListener</span><span class="o">);</span> </span></pre></div> </td></tr></table>
android