机器人:在使用的onDestroy IntentService()(Android: IntentS

2019-10-18 08:01发布

我试图删除数据库中的一个especific注册表一旦用户退出应用程序。 对于这个问题我叫伟驰theorically运行时的应用程序ID摧毁一个IntentService。 问题在于,尽管如预期和注册表不会被删除此意图不工作。 这里是如果你可以帮助代码。 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。 然而,在某些情况下(1出的30)的synctask做了它的任务。

Answer 1:

实际上onDestroy方法不能调用。

onDestroy是你的活动称为只有当系统资源不足(内存,CPU时间等),并作出决定杀死你的活动/应用程序或当有人呼叫完成()。

如果你想释放一些资源,你应该做的是,在 onPause() 来代替。



文章来源: Android: IntentService used in onDestroy()