further clarification on form service

11 views
Skip to first unread message

Brian Cohen

unread,
Jul 8, 2013, 9:16:27 AM7/8/13
to alternate-java-bridg...@googlegroups.com
This question is mostly directed at Ryan, but I figured I would start a thread instead of emailing him directly, that way others can benefit, or if you have something to contribute, please do.

Ryan, we talked a few weeks ago about how form service doesnt really work EXACTLY like a service does in android.  If I remember correctly, you were basically saying that a form service is just a form without a UI, and that if the app receives a destroy command (although i think a stop command as well from my experience), then it won't perform the code in the form service.

Here is what is going on....

I am trying to perform an email send through a form service.  I have an app with a UI, i fill out some email stuff, just a time in the future, and hit "schedule message".  At that time, an alarm is scheduled for that specified time.  At that time, the alarm launches a form service.  this form service sends the email.  

After a ton of troubleshooting, where sometimes the message goes, and other times it doesn't, and even other times it does, but much later than expected, I believe the issue is that the app has to be open and in the foreground, or the message won't send.



So... my question is two fold.

1, is this how form service is supposed to work?

and 2, given my project outline above, can you recommend a better way for scheduling something to be performed in the background at a given time?

Thanks, I know you are super busy, I appreciate any insight you can provide

Brian Cohen

unread,
Jul 9, 2013, 10:13:24 AM7/9/13
to alternate-java-bridg...@googlegroups.com
I am using the mail class from this website 


It appears to use some sort of handler.  I am very unfamiliar with using handlers.

My app basically sets an alarm that runs the send command from that class in a one time thread.


On Mon, Jul 8, 2013 at 5:16 PM, kenneth rankin <a54S...@gmail.com> wrote:

Are you currently using a handler?

--
You received this message because you are subscribed to the Google Groups "Java Bridge Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to alternate-java-bridge-libr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Imp Inc

unread,
Jul 9, 2013, 8:28:38 PM7/9/13
to alternate-java-bridg...@googlegroups.com
Actually a FormService IS an Android service. That's the class it extends. Sure there are methods like a Form, but those are there for simplicity's sake (and a service is close to an Activity in how it operates, in fact they both extend the Context class).

The code in that link looks fine. I don't think the issue is the Mail class.

One thing you could try is running the service in the foreground. This will allow the service to run as if it's in the foreground when the app is not. This requires a notification to be placed in the device's notification bar.

I'll be adding a method to call this easily (actually I have already, but my copy of the bridge is kind of in flux at the moment).

Here's the method if you want to try it out:

/**
     * Use this method to set this service as a Foreground service. This means it will behave
     * as if it is in the foreground, even if the app is not. This will consume more battery,
     * so use this wisely. Also, a notification is placed in the notification bar (this is required),
     * hence the need for the text, and icon res it.
     *
     * @param iconResId    The resource ID of the icon you wish to display in the notification
     *
     * @param titleText The title of the notification.
     *
     * @param tickerText The text which shows in the notification bar when a notification is first
     * displayed.
     *
     * @param msgText The text that is displayed in the notification when vieweing current notifications
     *
     * @param classToOpen The class to open when the notification is clicked.
     */
    @SuppressWarnings("deprecation")
    public void ForeGround(int iconResId, String titleText, String tickerText, String msgText, Class<?> classToOpen) {
        Notification note = new Notification(iconResId, tickerText, System.currentTimeMillis());
        Intent intent = new Intent(this, classToOpen);
        PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
        note.setLatestEventInfo(this, titleText, msgText, pIntent);
        startForeground(FOREGROUND_ID, note);
    }

Ryan
To unsubscribe from this group and stop receiving emails from it, send an email to alternate-java-bridge-library-discussion+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages