Skip to content

Instantly share code, notes, and snippets.

@sejas
Last active March 25, 2017 21:56
Show Gist options
  • Save sejas/6b6071a835721fcd91f84347beeb00a3 to your computer and use it in GitHub Desktop.
Save sejas/6b6071a835721fcd91f84347beeb00a3 to your computer and use it in GitHub Desktop.
//PASS STRING TO ACTIVITY
Intent intentToStartDetailActivity = new Intent(context, destinationClass);
intentToStartDetailActivity.putExtra(Intent.EXTRA_TEXT,"Hellow World!");
startActivity(intentToStartDetailActivity);
//GET STRING IN ACTIVITY CHILD
Intent intentThatStartedThisActivity = getIntent();
if (intentThatStartedThisActivity.hasExtra(Intent.EXTRA_TEXT)) {
String textEntered = intentThatStartedThisActivity.getStringExtra(Intent.EXTRA_TEXT);
detailTV.setText(textEntered);
}
public void onClickOpenAddressButton(View v) {
String addressString = "plaza mayor 1, Madrid";
Uri.Builder builder = new Uri.Builder();
builder.scheme("geo")
.path("0,0")
.query(addressString);
Uri addressUri = builder.build();
showMap(addressUri);
}
private void showMap(Uri geoLocation) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(geoLocation);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
public void onClickOpenWebpageButton(View v) {
String urlAsString = "https://sejas.es";
openWebPage(urlAsString);
}
private void openWebPage(String url) {
// Use Uri.parse to parse the String into a Uri
Uri webpage = Uri.parse(url);
// Create an Intent with Intent.ACTION_VIEW and the webpage Uri as parameters
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
// Verify that this Intent can be launched and then call startActivity
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment