Skip to content

Instantly share code, notes, and snippets.

@Razeeman
Razeeman / PersistentData.java
Last active January 30, 2019 12:42
Android, Java, onSaveInstanceState.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*
* If savedInstanceState is not null, that means our Activity is not being started for the
* first time. Even if the savedInstanceState is not null, it is smart to check if the
* bundle contains the key we are looking for.
*/
if (savedInstanceState != null) {
@Razeeman
Razeeman / ImplicitIntents.java
Last active January 30, 2019 17:52
Android, Java, Implicit intents, Open webpage, Open map, Share text.
/**
* This method fires off an implicit Intent to open a webpage.
*
* @param url Url of webpage to open. Should start with http:// or https:// as that is the
* scheme of the URI expected with this Intent according to the Common Intents page
*/
private void openWebPage(String url) {
Uri webpage = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
/*
@Razeeman
Razeeman / AsyncTask.java
Last active January 30, 2019 12:44
Android, Java, AsyncTask.
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
query = "sample query"
URL searchUrl = NetworkUtils.buildUrl(query);
new QueryTask().execute(searchUrl);
@Razeeman
Razeeman / NetworkUtils.java
Last active January 30, 2019 12:45
Android, Java, Network, Build Url, Build Uri, HttpURLConnection.
/**
* Builds the URL from query string.
*
* @param searchQuery The search string that will be queried for.
* @return The URL to use for the query.
*/
public static URL buildUrl(String searchQuery) {
String baseUrl = "https://api.github.com/search/repositories";
String paramQuery = "q";
@Razeeman
Razeeman / links.txt
Last active May 26, 2019 08:33
Android/Java useful links