Android instance-Mobile security Defender (15)-from the main interface into the mobile phone anti-theft interface

Source: Internet
Author: User

First, the goal

1, in the main interface through the "Set anti-theft password" or "Enter the anti-theft password", the dialog disappears, and enter the "mobile phone anti-theft interface."

2, enter is "mobile phone anti-theft interface", according to whether or not complete the "mobile phone anti-Theft Setup Wizard" situation into a different interface. If not completed, then enter the wizard interface, if completed, then enter the anti-theft interface.

Second, the code implementation.

1. Create a new two activity (named Securityactivity and SetupWizard) under the package (Com.example.mobilesafe) and complete the registration in the configuration file (Androidmanifest.xml). Securityactivity is used for the implementation of the "mobile phone anti-theft" feature, SetupWizard for the Anti-Theft Setup wizard. Complete the implementation of the OnCreate method in each new class at the same time.

2, under the layout package to establish the new two class of layouts (named Activity_security.xml and Activity_setupwizard_ui1.xml respectively), Activity_security.xml for the design " Mobile Anti-Theft Interface (securityactivity) Ui,activity_setupwizard_ui1.xml is used to design the first page UI of the mobile anti-Theft Setup wizard interface. The phone anti-Theft Setup wizard interface code and layout file are associated with Setcontentview.

3, in the main interface (homeactivity) "pop-up set anti-Theft Password dialog box" (Showsetpwddialog) and "pop-up input anti-Theft Password dialog box" (Showinputpwddialog) two methods, when the password is set or entered correctly, Activate the "Phone anti-Theft" class (securityactivity) via intent.

The main interface into the "mobile phone anti-theft Interface" code is as follows (note: Two methods need to join):

1 Intent Intent =new Intent (homeactivity.  this, securityactivity. class ); 2                     StartActivity (Intent);
View Code

4, in the "mobile phone anti-theft" class (Securityactivity) code, through the Sharedpreferences object in the Wave Boolean type parameter (SetupWizard) value to determine whether to enter the "mobile phone anti-theft interface" or start the "mobile Anti-Theft Settings Wizard" class.

①. Define a private sharedpreferences member variable (SP) in the "Phone anti-Theft" class (Securityactivity), in the OnCreate method, Gets the name (string name) as "config" through the getsharedpreferences (string name, int mode) of the Sharedpreferences object (SP) The Sharedpreferences object, type (int mode) is mode_private.

② gets the key named "SetupWizard" through the Getboolean (String key, Boolean Defvalue) method of the Sharedpreferences object (SP) The value of the Boolean type (named SetupWizard).

③. If...else statement to determine the value (SetupWizard), if true, then enter the "phone anti-theft" interface, if false, through the intent method to start the Setup wizard (SetupWizard) class, and close the current page "Securityactivity" by the Finish () method.

Mobile phone anti-theft class (Securityactivity) code:

1  Public classSecurityactivityextendsActivity {2     Privatesharedpreferences sp;3     4 @Override5     protected voidonCreate (Bundle savedinstancestate) {6         Super. OnCreate (savedinstancestate); 7         //Determine if the Setup wizard has completed, and if none, go to the Setup wizard. 8SP = getsharedpreferences ("config", mode_private);9         BooleanSetupWizard = Sp.getboolean ("SetupWizard",false);Ten         if(setupwizard) { One Setcontentview (r.layout.activity_security); A}Else { -Intent Intent =NewIntent (securityactivity. This, SetupWizard.class); - startactivity (Intent);  the finish (); -         } -     } -}
View Code

Android instance-Mobile security Defender (15)-from the main interface into the mobile phone anti-theft interface

Related Article

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.