Fetching messages from a server

by Kevin Anthony » Sun, 27 Mar 2011 00:25:00 GMT

Sponsored Links
 I have an application that needs to fetch messages from a server,
currently i do this via a service, running in the background.
However, when my application is not in the foreground, it quickly gets
pushed out of memory, and stops checking for messages.

I've been playing with AbstractThreadedSyncAdapter, but this seems a
little heavy handed.

Is there some middle ground?  Something i should look into?

Kevin Anthony


Re: Fetching messages from a server

by Mark Murphy » Sun, 27 Mar 2011 00:32:53 GMT

 On Sat, Mar 26, 2011 at 12:24 PM, Kevin Anthony

This is a good thing. An everlasting service like this is an
anti-pattern and should be avoided wherever possible.

little heavy handed.

Could be -- I haven't had a chance to mess with that yet.

Use AlarmManager and fetch the messages on a periodic basis, with the
user controlling the polling frequency (including an option for
manual-refresh-only) via a SharedPreference.

Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://github.com/commonsguy 
 http://commonsware.com/blog  |  http://twitter.com/commonsguy 

Android Training in London:  http://bit.ly/smand1 ,  http://bit.ly/smand2 


Sponsored Links

Re: Fetching messages from a server

by Kevin Anthony » Mon, 28 Mar 2011 06:40:50 GMT

 Thanks, that did the trick

Kevin Anthony


Other Threads

1. Cannot modify a button from the menu


I am writing a program that has a menu. Once you press the menu button
and then select "Left",  it's supposed to change the attributes of
myButton12, an ImageButton.

However, I am getting a "myButton12 cannot be resolved" error message.
Please help me figure out what is wrong with this code.


The code:

package com.innodesign.testingbuttons;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AbsoluteLayout;
import android.widget.ImageButton;
import android.widget.Button;
import android.widget.EditText;
import android.net.Uri;
import android.content.Intent;

public class TestingButtons extends Activity {
        protected void onCreate(Bundle icicle) {

                final ImageButton myButton12 = (ImageButton) findViewById
                myButton12.setOnClickListener(new View.OnClickListener()
                public void onClick(View v) {
                // Perform action on click

    public boolean onCreateOptionsMenu(Menu menu){

                menu.add(0, 1, 0, "Left");
                menu.add(0, 2, 0, "Right");
    return true;

        public boolean onOptionsItemSelected(MenuItem item){
                case 1:
                return true;
                case 2:
                return true;
        return true;

        public void shiftLeft(){
                myButton12.setLayoutParams(new AbsoluteLayout.LayoutParams(10, 
10, 10));



2. download question

Hi all:
        I had defined some interfaces in a C file by using WININET
APIs like InternetOpen, InternetConnect, HttpOpenRequst and so on. All
these functions return a hundle indicate the connection or a request
header. Now i want to transplant my program to android and keep the
interfaces changeless( include the parameters and return type)
       I had consulted the android api, but didn't know which class to
       Waiting for your advises.Thank all.



3. is there a way to access the install date of an application?

4. Need ideas on implementing a Trial Period for a free app on Android Market

5. How to update View object on main thread by background thread

6. How to disable 3G/GRPS

7. Can't open dex cache error with SDK 1.1