Android:onDestroy()中使用的IntentService [英] Android: IntentService used in onDestroy()

查看:233
本文介绍了Android:onDestroy()中使用的IntentService的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在用户退出应用程序后在数据库中删除特定的注册表.对于这个问题,我调用了IntentService,当应用程序ID销毁时,它会在理论上运行.问题是,尽管此意图无法按预期运行,并且不会删除注册表.如果您需要帮助,请参见以下代码. IntentService:

I am trying to delete a especific registry in a database once the user quits the app. For that issue I call an IntentService whichs runs theorically when the application id destroyed. The problem is that, although this intent does not work as intended and the registry is not deleted. Here is the code if you may help. 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可以完成其任务.

I tried to use Asynctask before but I could not get the desired effect when onDestroy. however, in some cases (1 out of 30) the synctask did its task.

推荐答案

实际上 onDestroy 方法无法调用.

Actually onDestroy method can not be called.

onDestroy 仅被调用当系统资源不足(内存,CPU时间等)并决定终止您的活动/应用程序,或者有人对您的活动调用finish()时.

onDestroy is called only when system is low on resources(memory, cpu time and so on) and makes a decision to kill your activity/application or when somebody calls finish() on your activity.

如果要释放一些资源,则应在 中执行此操作.

If you want to release some resources, you should do that in onPause() instead.

这篇关于Android:onDestroy()中使用的IntentService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆