[Apidemos for Android samples video series] app-activity-redirection

Source: Internet
Author: User

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:

 
  1. // Retrieve the current text preference. If there is no text
  2. // Preference set, we need to get it from the user by invoking
  3. // Activity that retrieves it. To do this cleanly, we will
  4. // Temporarily hide our own activity so it is not displayed until
  5. // Result is returned.
  6. If (! Loadprefs ()){
  7. Intent intent = new intent (this, redirectgetter. Class );
  8. Startactivityforresult (intent, init_text_request );
  9. }

 

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.