如何正确使用Volley库与IntentService?

时间:2016-03-15 13:42:04

标签: java android android-volley fatal-error intentservice

我对Volley库有问题。我正在测试这个库,我在三星S5上10分钟后收到错误。

以下是我的简单示例代码:

public class SimpleWakefulService extends IntentService {

    public SimpleWakefulService() {
        super("SimpleWakefulService");
    }

    boolean success = true;

    JSONArray t = new JSONArray();
    JSONArray o = new JSONArray();
    JSONArray m = new JSONArray();

    @Override
    protected void onHandleIntent(Intent intent) {

        RequestQueue queue = Volley.newRequestQueue(this);

        StringRequest postRequest = new StringRequest(Request.Method.POST, PROT + "://" + REMOTE + "/" + DIR + "/repeat.php",
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {

                        try {
                            JSONObject result = new JSONObject(response);
                            success = result.getBoolean("success");
                            t = result.getJSONArray("t");
                            o = result.getJSONArray("o");
                            m = result.getJSONArray("m");
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        Intent intent = new Intent(getApplicationContext(), Zlecenia.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);

                        alarm();

                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {

                        searchsignal();

                    }
                }
        ) {
            @Override
            protected Map<String, String> getParams()
            {

                GlobalConfig config = new GlobalConfig();
                JSONObject json = config.getConfig();
                JSONObject location = config.getLocation();

                JSONObject data = new JSONObject();

                try {

                    data.put("ID", json.getString("ID"));
                    data.put("session", json.getString("session"));

                    if(location != null) {

                        data.put("latitude", location.getString("latitude"));
                        data.put("longitude", location.getString("longitude"));

                    }

                    if(Strefa.Tabela){
                        data.put("tabela", true);
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }

                Map<String, String>  params = new HashMap<String, String>();
                params.put("json", data.toString());

                return params;
            }

        };

        postRequest.setRetryPolicy(new DefaultRetryPolicy(
                5000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        queue.add(postRequest);

        SimpleWakefulReceiver.completeWakefulIntent(intent);

    }

    public void alarm() {

        Intent intent = new Intent(this, SimpleWakefulReceiver.class);
        GlobalConfig.pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
        GlobalConfig.alarmManager = (AlarmManager) this.getSystemService(ALARM_SERVICE);

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
            GlobalConfig.alarmManager.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 3000, GlobalConfig.pendingIntent);
        } else {
            GlobalConfig.alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 3000, GlobalConfig.pendingIntent);
        }

    }

}

我坐下来观察屏幕。我在等待......我的空间减弱了,经过10分钟后看到错误:

03-15 13:36:29.121 10969-11275/com.example.seadog.gps E/qdmemalloc: ion: Failed to map memory in the client: Out of memory
03-15 13:36:29.121 10969-11275/com.example.seadog.gps E/qdgralloc: Could not mmap handle 0x6210d100, fd=50 (Out of memory)
03-15 13:36:29.121 10969-11275/com.example.seadog.gps E/qdgralloc: gralloc_register_buffer: gralloc_map failed
03-15 13:36:29.121 10969-11275/com.example.seadog.gps W/GraphicBufferMapper: registerBuffer(0x6210d100) failed -12 (Out of memory)
03-15 13:36:29.121 10969-11275/com.example.seadog.gps E/GraphicBuffer: unflatten: registerBuffer failed: Out of memory (-12)
03-15 13:36:29.121 10969-11275/com.example.seadog.gps E/Surface: dequeueBuffer: IGraphicBufferProducer::requestBuffer failed: -12
03-15 13:36:29.121 10969-11275/com.example.seadog.gps W/Adreno-EGLSUB: <DequeueBuffer:720>: dequeue native buffer fail: Out of memory, buffer=0x0, handle=0x0
03-15 13:36:29.121 10969-11275/com.example.seadog.gps W/Adreno-EGL: <qeglDrvAPI_eglSwapBuffers:3702>: EGL_BAD_SURFACE
03-15 13:36:29.121 10969-11275/com.example.seadog.gps W/OpenGLRenderer: swapBuffers encountered EGL_BAD_SURFACE on 0x621739c0, halting rendering...
03-15 13:36:29.151 10969-11275/com.example.seadog.gps A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x54 in tid 11275 (RenderThread)

0 个答案:

没有答案