The processing method of the thread in Android _android

Source: Internet
Author: User
Tags getmessage gettext stub

The example of this article is about the method of dealing with the thread in Android. Share to everyone for your reference. The specific methods are as follows:

I now register with a user feature
1. Use ProgressDialog to set the current page to be not operable (leave the return key to exit ProgressDialog)
2. Execute data submission and return with one thread Clientthread

Question: In view of the ProgressDialog operation, the return key operation, should terminate the clientthread operation.

The code is as follows, interested friends can refer to the run, in order to come up with a better solution.

Copy Code code as follows:

Btn_register.setonclicklistener (New View.onclicklistener () {

@Override
public void OnClick (View v) {
TODO auto-generated Method Stub
if (Dobeforesubmit ()) {

try {
LOG.V (TAG, "Clientthread prepare01 ...) : "+thread.interrupted ());
Clienthread=new Thread () {
public void Run () {
try {
LOG.V (TAG, "Clientthread prepare02 ...) : "+thread.interrupted ());
while (! Thread.interrupted ()) {
LOG.V (TAG, "clientthread starting ...) ");
Meapicall meapicall=new Meapicallimpl ();
Me me=new Me ();
Me.setmeemail (Et_register_account.gettext (). toString (). Trim ());
Me.setmepwd (Et_register_pwd.gettext (). toString (). Trim ());
Me.setmename (Et_register_nickname.gettext (). toString (). Trim ());
LOG.V (TAG, "Clientthread data Loaded ... ");
Meapicall.register (Me);
LOG.V (TAG, "Clientthread callback ...) ");
Handler.sendemptymessage (AppConfig.Register.SUCCESS_MSG);
Clienthread.interrupt (); Interrupt Thread in
}
catch (Interruptedexception e) {
Todo:handle exception
LOG.V (TAG, "Clientthread is Interrupt");
}catch (Exception e) {
TODO auto-generated Catch block
LOG.V (TAG, "Exception:" +e.getmessage ());
Handler.sendemptymessage (AppConfig.Register.FAIL_OTHER_MSG);
E.printstacktrace ();
}
};
};
LOG.V (TAG, "ProgressDialog prepare01 ...) :");
Progressdialog=progressdialog.show (Register.this,
"",
"Getting ...",
True
True
New Dialoginterface.oncancellistener () {

@Override
public void OnCancel (Dialoginterface dialog) {
TODO auto-generated Method Stub

try {
Clienthread.interrupt ();
LOG.V (TAG, "Interrupt is success!");
catch (Exception e) {
TODO auto-generated Catch block
LOG.V (TAG, "Interrupt is fail!");
E.printstacktrace ();
}
}
}
);
LOG.V (TAG, "Clientthread prepareing_end ...) ");
Clienthread.start ();
LOG.V (TAG, "Clientthread prepareing_end ...) ");
catch (Exception e) {
TODO auto-generated Catch block
LOG.V (TAG, e.getmessage () + "00");
E.printstacktrace ();
}
}
}
});

I hope this article will help you with your Android program.

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.