我想要一些代码在后台持续运行.我不想在服务中这样做.还有其他方法吗?
我曾尝试Thread在我的课程中调用课程,Activity但我的Activity遗体在后台停留了一段时间然后停止了.该Thread课程也停止工作.
class testThread implements Runnable {
@Override
public void run() {
File file = new File( Environment.getExternalStorageDirectory(), "/BPCLTracker/gpsdata.txt" );
int i = 0;
RandomAccessFile in = null;
try {
in = new RandomAccessFile( file, "rw" );
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//String line =null;
while ( true ) {
HttpEntity entity = null; …Run Code Online (Sandbox Code Playgroud)