我试图在用户退出应用程序后删除数据库中的特定注册表。对于那个问题,我调用一个IntentService,当应用程序ID被销毁时,它会以理论方式运行。问题是,虽然此意图不能按预期工作,但注册表不会被删除。如果您愿意,可以使用以下代码。 IntentService:
public class FinIntentService extends IntentService{
String levelstring = "22";
int pid;
static String pids;
BroadcastReceiver batteryReceiver = null;
String url = "10.0.0.13";
private static String url_crear = "http://10.0.0.13/subida/create_candidato.php";
private static final String url_delete = "http://10.0.0.13/subida/delete_candidato.php";
JSONParser jsonParser = new JSONParser();
@SuppressLint("NewApi")
static String device_id = Build.SERIAL;
static String PDA = device_id.substring(device_id.length() - 6);
public FinIntentService() {
super("FinIntentService");
}
@Override
protected void onHandleIntent(Intent intent)
{
int success;
try {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("id", Titulacion.getPID()));
JSONObject json = jsonParser.makeHttpRequest(
url_delete, "POST", params);
Log.d("Delete Product", json.toString());
success = json.getInt("success");
} catch (JSONException e) {
e.printStackTrace();
}
}
}
未达到日志
主要活动:
public void onDestroy(){
super.onDestroy();
Intent msgIntent = new Intent(Titulacion.this, FinIntentService.class);
startService(msgIntent);
}
我之前尝试过使用Asynctask但是在onDestroy时我无法获得所需的效果。然而,在某些情况下(30个中的1个),synctask完成了它的任务。