Android thread enabling and stopping (using java Technology for reference), androidjava

Source: Internet
Author: User

Android thread enabling and stopping (using java Technology for reference), androidjava

In The onclick () Click Event

// Upload the geographic location

Case R. id. person_up_locat:
System. out. println ("=== = output .... ==== ");
// StartActivity (new Intent (PersonCenterActivity. this,
// AddedToolsActivity. class ));
// Obtain the geographical location-Longitude and latitude and coordinates
String addrStr = response data. getinclustringdata ("addrStr ");
String latit = response data. getinclustringdata ("latit ");
String longit = response data. getinclustringdata ("longit ");
String urloca = HttpUrl. HttpLIPEI
+ "/Yqw/w/c/post? App = survey & mdl = web & act = getSurveyLonLatList"
+ "& Type = json & token = 1 ";
// + "& Col. surveyId =" + surveyId
UrlLo = urllca + "& 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,300 0 );
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,100 0 );//
// Execute the task after S and execute the task again after 1 s

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

// Use do, while, do --- to start the thread and upload data

Do {

LocationLLA = HttpService. postParamAndFile (urlLo );
System. out. println ("upload location ------- 33 --" + urlLo
+ "=" + LocationLLA );

} While (FLAG = 1 );

// While (FLAG = 1); --- stop closing the thread and close the data

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


} Catch (Exception e ){
// TODO Auto-generated catch block
E. printStackTrace ();
}
}
}, 100,300 0 );


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 location ----- 00--22 --");
}
System. out. println ("= FLAG = 2 =" + FLAG );
Break;
Default:
Break;
How to stop a java thread

You have a problem with implementation,
Are there any inherited thread classes or Runnable implementations?
If this is not the case, you want to create an endless loop in the same thread.

The following is an example. For more information,
Starting from, excessive entries are moving. Clicking pause will stop, and then clicking pause will start again.
Click stop to stop. Take a look.
----------------------------------------------------------------
Import java. awt. Dimension;
Import java. awt. Toolkit;

Import javax. swing. JFrame;
Import javax. swing. JLabel;
Import javax. swing. JProgressBar;
Import javax. swing. JToolBar;
Import javax. swing. JButton;
Import java. awt. event. ActionListener;
Import java. awt. event. ActionEvent;

Public class Table extends JFrame implements Runnable {

Private JProgressBar progress = new JProgressBar ();
Private boolean start = false;
Private boolean pause = false;
Private JButton btnStart;

Public Table (){
SetResizable (false );

GetContentPane (). setLayout (null );

JToolBar toolBar = new JToolBar ();
ToolBar. add (new JLabel ("state "));
ToolBar. add (progress );
ToolBar. setFloatable (false );
ToolBar. setBounds (0,247,454, 21 );
GetContentPane (). add (toolBar );

BtnStart = new JButton ("start ");
BtnStart. addActionListener (new ActionListener (){
Public void actionreceivmed (ActionEvent e ){
Login ();
}
});
BtnStart. setBounds (12, 10, 91, 21 );
GetContentPane (). add (btnStart );

JButton btnPause = new JButton ("Pause ");
BtnPause. addActionListener (new ActionListener (){
Public void actionreceivmed (ActionEvent e ){
Pause =! Pause;
}
});
BtnPause. setBounds (131, 10, 91, 21 );
GetContentPane (). add (btnPause );

JButton btnStop = new JButton ("stop & quot ...... remaining full text>

How to stop a running thread in android

After 2.2, press the home Key and leave it in the task manager to operate on the thread.

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.