Android thread start and stop (learn Java technology)

Source: Internet
Author: User

In the onclick () Click event

Upload Location

Case R.ID.PERSON_UP_LOCAT:
System.out.println ("= = = output ....) ====");
StartActivity (New Intent (Personcenteractivity.this,
Addedtoolsactivity.class));
Get geolocation-latitude and longitude and coordinates
String addrstr = Sharedata.getsharestringdata ("Addrstr");
String latit = Sharedata.getsharestringdata ("Latit");
String longit = Sharedata.getsharestringdata ("Longit");
String Urlloca = Httpurl.httplipei
+ "/yqw/w/c/post?app=survey&mdl=web&act=getsurveylonlatlist"
+ "&type=json&token=1";
+ "&col.surveyid=" + Surveyid
Urllo = Urlloca + "&col.lon=" + longit + "&col.lat=" + latit
+ "&col.addressinfo=" + addrstr;
System.out.println ("= = = output ....) ==2== ");
Final String Locationlla = Httpservice.postparamandfile (Urllo);
Mtime.schedule (New Remindtask (), 100, 3000);
Final Timer mtime = new timer ();
TimerTask Mtask;
Mtime.schedule (New TimerTask () {
@Override
public void Run () {
try {
System.out.println ("=flag=0=" + FLAG);
Mtime.schedule (Mtask, 100, 1000);//
Execute task after 0.1s and execute again after 1s

System.out.println ("Upload location-------11--");

Using the Do,while method, do---Start the thread, upload the data

do {

Locationlla = Httpservice.postparamandfile (Urllo);
System.out.println ("Upload location-------33--" + Urllo
+ "= = =" + Locationlla);

} while (FLAG = = 1);

while (FLAG = = 1); ---Stop shutting down the thread and closing the data

Mtime.cancel ();
System.out.println ("Do not upload geographic location-------22--");


} catch (Exception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
} , (+);


System.out.println ("=flag=1=" + FLAG);
if (FLAG = = 0) {
First_visib.setvisibility (View.gone);
First_gone.setvisibility (view.visible);
FLAG = 1;
System.out.println ("===00====0======");
} else if (FLAG = = 1) {
System.out.println ("===0===2======");
First_visib.setvisibility (view.visible);
First_gone.setvisibility (View.gone);
FLAG = 0;
System.out.println ("Do not upload geographic location-----00--22--");
}
System.out.println ("=flag=2=" + FLAG);
Break
Default
Break

Android thread start and stop (learn Java technology)

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.