1. Demo description and demonstration
Redirection this demo involves three acitifications: redirectenter, redirectmain, redirectgetter. Its main activity is redirectenter, which starts redirectmain and determines whether to start redirectgetter again in redirectmain based on the conditions. The main knowledge point is the use of sharedpreference.
The demo is as follows:
2. Video description
Http://www.eyeandroid.com/thread-10683-1-1.html
3. Demo Analysis
The redirection example involves three acitifications: redirectenter, redirectmain, and redirectgetter. In the example, the main activity is redirectenter, and redirectenter starts redirectmain, and the activity determines whether to pass the control of the application to redirectgetter or keep it in redirectmain based on a certain condition.
Shared preferences is used in the application code (introduced in the previous example ). Redirectmain checks whether a shared preferences value exists:
- // Retrieve the current text preference. If there is no text
- // Preference set, we need to get it from the user by invoking
- // Activity that retrieves it. To do this cleanly, we will
- // Temporarily hide our own activity so it is not displayed until
- // Result is returned.
- If (! Loadprefs ()){
- Intent intent = new intent (this, redirectgetter. Class );
- Startactivityforresult (intent, init_text_request );
- }
Startactivityforresult is also used. This example has no new knowledge, but involves three activities. Demonstrate how to trigger different activities based on conditions and apply control redirection to different activities.
In this example, you click the "go" button and redirectenter starts redirectmain. redirectmain determines whether to redirect to redirectgetter based on shared preferences. After you click "clear and exit" for the first time, shared preferences does not contain text values. The application displays the user input obtained by redirectgetter. If the user input is "Apply", redirectgetter stores the textview value in shared preference. After that, press "back" to return to the activity list and start redirectenter. Press "go". Because shared preferences have values, rediectmain does not redirect control of the application to redirectgetter.