'How to refactor getIntent() code to use parseUri() instead?
According to getIntent documentation, the method was deprecated in Android API 15. Instead, we are recommended to "Use parseUri(String, int) instead." and to "Call parseUri(String, int) with 0 flags."
This advice is kind of confusing since getIntent could be called without arguments. For example, here is a code snippet from a Udacity course exercise using the old API:
MainActivity.java
/*
* Here, we create the Intent that will start the Activity we specified above in
* the destinationActivity variable. The constructor for an Intent also requires a
* context, which we stored in the variable named "context".
*/
Intent startChildActivityIntent = new Intent(context, destinationActivity);
/*
* We use the putExtra method of the Intent class to pass some extra stuff to the
* Activity that we are starting. Generally, this data is quite simple, such as
* a String or a number. However, there are ways to pass more complex objects.
*/
startChildActivityIntent.putExtra(Intent.EXTRA_TEXT, textEntered);
/*
* Once the Intent has been created, we can use Activity's method, "startActivity"
* to start the ChildActivity.
*/
startActivity(startChildActivityIntent);
ChildActivity.java
/*
* Here is where all the magic happens. The getIntent method will give us the Intent that
* started this particular Activity.
*/
Intent intentThatStartedThisActivity = getIntent();
How would I refactor ChildActivity.java to use parseUri instead of getIntent?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
