Android Phone Defender--Popup dialog box

Source: Internet
Author: User

In the article "Android Phone defender-parsing JSON and message mechanism send different types of messages," the message mechanism to send different types of information has not been fully implemented, in the event of an exception, should pop up a toast tip exception, the code is as follows:

    PrivateHandler Mhandler =NewHandler () {//         Public voidhandlemessage (android.os.Message msg) {Switch(msg.what) { Caseupdate_version://Pop-up dialog box prompting user to update//Showupdatedialog ();                 Break;  CaseEnter_home://go to the application main interface, activity jump processEnterhome ();  Break;  CaseURL_ERROR:ToastUtil.show (Getapplicationcontext (),"URL Exception");                Enterhome ();  Break;  CaseIO_ERROR:ToastUtil.show (Getapplicationcontext (),"Read Exception");                Enterhome ();  Break;  CaseJSON_ERROR:ToastUtil.show (Getapplicationcontext (),"JSON parsing exception");                Enterhome ();  Break; default:                 Break;    }        }; };

Because the pop-up toast operation is more common, so it is written as a tool class for a simple package, easy to call later.

This article address: http://www.cnblogs.com/wuyudong/p/5902161.html, reprint please indicate source address.

Then the new tool class: Toastutil.java

 Packagecom.wuyudong.mobilesafe.Utils;ImportAndroid.content.Context;ImportAndroid.widget.Toast; Public classToastutil {//Print Toast        /**     * @paramContext Environment *@parammessage Print text content*/     Public Static voidShow (context context, String message) {Toast.maketext (context, message,0); }}

If the current version number < server version number, a dialog box prompts for updates

    /*** Pop-up dialog box prompting user to update*/    protected voidShowupdatedialog () {System.out.println ("Showupdatedialog"); //dialog box, which is dependent on the presence of the activityBuilder Builder =NewAlertdialog.builder ( This); //set the upper left corner iconBuilder.seticon (R.drawable.ic_launcher); Builder.settitle ("Version Update"); //Setting Description Contentbuilder.setmessage (mversiondes); //Active button, update nowBuilder.setpositivebutton ("Update Now",NewOnclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) {                //download apk,apk link address, DownloadURL downloadapk ();        }        }); Builder.setnegativebutton ("Say it later,"NewOnclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) {                //Cancel the dialog box and go to the main interfaceEnterhome ();        }        });    Builder.show (); }

The effect of the implementation is as follows:

where the downloadapk () function is implemented in the following article

Android Phone Defender--Popup dialog box

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.