当前位置:编程学习 > wap >>

遇到looper小问题

如果在try {
server.backUpSmsToXml(list);
后面加Looper.prepare();
Toast.make();
Looper.loop();

finally里面的stopSelf();就无法执行,这是怎么回事,是跟looper有关吗?





package com.zyy.safe.service;

import java.util.List;

import com.zyy.safe.activity.HighToolsActivity;
import com.zyy.safe.activity.MainActivity;
import com.zyy.safe.bean.SmsInfo;
import com.zyy.safe.server.SmsInfoServer;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.IBinder;
import android.os.Looper;
import android.widget.ProgressBar;
import android.widget.Toast;

public class SmsBackUpService extends Service {
private NotificationManager nManager;

@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();

new Thread(new Runnable(){

@Override
public void run() {
// TODO Auto-generated method stub
nManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification=new Notification(android.R.drawable.stat_notify_sync,null,System.currentTimeMillis());
Intent intent=new Intent();
intent.setClass(getApplicationContext(), HighToolsActivity.class);
PendingIntent contentIntent=PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);

notification.flags=Notification.FLAG_AUTO_CANCEL;
SmsInfoServer server=new SmsInfoServer(SmsBackUpService.this);
List<SmsInfo> list = server.getSms();

try {
server.backUpSmsToXml(list);


notification.setLatestEventInfo(getApplicationContext(), "短信备份", "短信备份完成", contentIntent);
nManager.notify(1, notification);


} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
notification.setLatestEventInfo(getApplicationContext(), "短信备份", "短信备份失败", contentIntent);
nManager.notify(1, notification);


}finally{
System.out.println("-------------------------stop");
stopSlef();
}
}

}).start();
}

@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}

}
--------------------编程问答-------------------- 有没有人回答啊
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,