iBoston
iBoston

Reputation: 69

Android Alarm not firing when in separate process

The below code is from my MANIFEST.XML FILE

The below works :
<receiver android:name="com.PageP.Alarm>
But, when i add the process it doesn't fire :
<receiver android:process=":remote" android:name="com.PageP.Alarm>

I have a break point at : public void onReceive(Context context, Intent intent)

If no remote process, it works, if i add the remote process it stops working.

What am i missing???

OKAY, LET ME POST MY ASYNC HTTPGET

package com.PageP;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;

import android.os.AsyncTask;

public class GrabURL extends AsyncTask<String, Void, Void> {
    private HttpClient Client = new DefaultHttpClient();
    private String content;
    private String Error = null;
    private String url = null;

    protected void onPreExecute() {
 //       Dialog.setMessage("Downloading source..");
 //       Dialog.show();
    }

    protected Void doInBackground(String... urls) {
        url = urls[0];
        try {
            HttpGet httpget = new HttpGet(urls[0]);
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            content = Client.execute(httpget, responseHandler);
        } catch (ClientProtocolException e) {
            Error = e.getMessage();
            cancel(true);
        } catch (IOException e) {
            Error = e.getMessage();
            cancel(true);
        }

        return null;
    }

    protected void onPostExecute(Void unused) {
      Login.GotURL(content, url);
      Client = null;
    }

}

AND THEN I CALL IT WITH

public static void Ping(String Args) {
 final GrabURL wget = new  GrabURL();
 String url = "";

 url = MyAuth("PING")+ Args;
 wget.execute(PPURL+url);
}

WHEN MY ALARM TRIGGERS, I WANT IT TOO STAY AWAKE TO RECEIVE THE DATA ON THE OTHER END WHERE I DECODE THE RETURNED HTML. I AM HAVING PROBLEMS WHERE WHEN THE ANDROID GOES INTO SLEEP MODE, IT ISN'T RELIABLY RECEIVING THE HTML RETURNED DATA.

Upvotes: 0

Views: 127

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006674

What am i missing?

Since having a separate process is generally a bad idea, just leave android:process off.

I need it to stay AWAKE long enough call a async wget and process the returned html.

I do not know what you consider an "async wget" to mean. I am going to assume that you literally mean that you are packaging an ARM-compiled wget binary with your app, which is bizarre beyond words.

Moreover, Android will terminate your process within seconds, for tying up the main application thread of that process. So you will waste RAM, CPU, and battery for no particular advantage.

Use HttpUrlConnection or HttpClient to do your HTTP request ("async wget"), from a WakefulIntentService, or your own IntentService that handles the WakeLock issues surrounding the use of _WAKEUP alarms. IntentService gives you a background thread (necessary for doing long-running work) and will automatically shut down when it is no longer needed (necessary so users don't attack you with task killers for harming their devices).

i could go into a do/loop and sleep within it waking up every 250 milli seconds to see if the data has come in

If you use HttpUrlConnection or HttpClient to do your HTTP request, you will know "if the data has come in" by virtue of those APIs.

with a set time out

If you use HttpUrlConnection or HttpClient to do your HTTP request, you will be able to specify a request timeout period.

Upvotes: 1

Related Questions