Last active
March 25, 2017 21:56
-
-
Save sejas/6b6071a835721fcd91f84347beeb00a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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