Android mobile guard-pop-up dialog box, android guard

Source: Internet
Author: User

Android mobile guard-pop-up dialog box, android guard

In the article "Android mobile guard-Parse json and message mechanisms to send different types of messages", message mechanisms have not yet been fully implemented to send different types of information. In the case of exceptions, the following code prompts an exception in the toast prompt:

Private Handler mHandler = new Handler () {// public void handleMessage (android. OS. message msg) {switch (msg. what) {case UPDATE_VERSION: // the pop-up dialog box prompts the user to update // showUpdateDialog (); break; case ENTER_HOME: // enter the main interface of the application. enterHome (); break; case URL_ERROR: ToastUtil. show (getApplicationContext (), "url exception"); enterHome (); break; case IO_ERROR: ToastUtil. show (getApplicationContext (), "Read exception"); enterHome (); break; case JSON_ERROR: ToastUtil. show (getApplicationContext (), "json parsing exception"); enterHome (); break; default: break ;}};};

As the pop-up toast operation is common, it is written as a tool class for simple encapsulation, so that it can be called later.

URL: http://www.cnblogs.com/wuyudong/p/5902161.html.

Create a tool class: ToastUtil. java

Package com. wuyudong. mobilesafe. utils; import android. content. context; import android. widget. toast; public class ToastUtil {// print Toast/*** @ param context Context * @ param message print text content */public static void show (context, String message) {Toast. makeText (context, message, 0 );}}

If the current version number is <server version number, an update prompt is displayed in the dialog box.

/*** Dialog box appears, prompting you to update */protected void showUpdateDialog () {System. out. println ("showUpdateDialog"); // the dialog box depends on the Builder builder = new AlertDialog of the activity. builder (this); // set the icon builder in the upper left corner. setIcon (R. drawable. ic_launcher); builder. setTitle ("version Update"); // sets the description content builder. setMessage (mVersionDes); // click the active button to update the builder immediately. setPositiveButton ("update now", new OnClickListener () {@ Override public void onClick (DialogInterface dialog, int which) {// download apk, apk URL, downloadUrl downloadApk () ;}}); builder. setNegativeButton ("later", new OnClickListener () {@ Override public void onClick (DialogInterface dialog, int which) {// cancel dialog box, enter enterHome ();}}); builder. show ();}

The implementation result is as follows:

The downloadApk () function is implemented in the next article.

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.