我创建了一个名为VPN服务的应用程序,它可以阻止互联网数据包。一切都很顺利,但现在我希望在点击按钮事件时停止这个VPN服务,以便数据包不再被阻塞。
我尝试使用“stopService(name)”和“stopSelf()”,但没有任何反应。我做错了什么?
我尝试使用“stopService(name)”和“stopSelf()”,但没有任何反应。我做错了什么?
public class VpnServiceCls extends VpnService {
private Thread b;
private ParcelFileDescriptor c;
private PendingIntent a;
Builder builder = new Builder();
private static final String TAG = "VpnService";
@Override
public void onDestroy() {
// TODO Auto-generated method stub
Log.d(TAG, "you are in jghbgjyhb");
if (b != null) {
Log.d(TAG, "you are in destroy2");
b.interrupt();
}
}
public void StopMyVPN()
{
Log.d(TAG, "you are in jghbgjyhb 898");
stopSelf();
if (b != null) {
Log.d(TAG, "you are in destroy");
b.interrupt();
}
b.stop();
super.onDestroy();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
b= new Thread(new Runnable() {
@Override
public void run() {
try{
//here is my logic which is working fine
}
}
catch(Exception e)
{
Log.d(TAG, "you are out "+e.toString());
}
}
});//start the service
b.start();
return START_STICKY;
}
}
当我点击按钮时,调用了 StopMyVPN() 函数,但什么也没有发生。