Same servicein multiple APKs, only want "best one" to launch

by Watcher » Fri, 18 Dec 2009 01:20:49 GMT


Sponsored Links
 Hi,

I have the same service in multiple APKs. In each of the APKs, I am
going to launch the serivce.
Because the APK are difference "applications" that have been installed
& upgraded at various times, the service implementation in each may be
different. I am trying to figure out a way to make sure startService()
runs the implementation that is newest.

I have been fiddling around with PackageManager and Manifest meta-data
and categories but I can't seem to get my head around it. It's really
a leader-election problem... has anyone ever done this ? Any clues ?

Thanks !

--



Other Threads

1. Intent not received

Hi I have a little problem with intents and intentreceiver

I have an application that stay at top and a service running in the
background.

I'm trying to broadcast an intent from the service to the activity.

i'm broadcasting the intent from the service with this code :
Log.i(TAG,"Message : USER_ID :"+res.elementAt(0));

Intent intent= new Intent( RECEIVED_MESSAGE_INTENT);
BundledMessage msg=new BundledMessage(res);
intent.putExtras(msg.getBundle());
broadcastIntent(intent);

in my activity , i have an intentreceveir as an innerclass , an
intentfilter and i'm registering the intent with this code :in
onCreate() :
myIntentFilter=new IntentFilter();
myIntentFilter.addAction(MessagesRetrieverService.RECEIVED_MESSAGE_INTENT);
this.myIntentReceiver = new MyIntentReceiver();
...
this.registerReceiver(this.myIntentReceiver, this.myIntentFilter);


class MyIntentReceiver extends IntentReceiver {
@Override
public void onReceiveIntent(Context context, Intent intent) {
Log.v(TAG, "intent:"+intent.getAction());

}

}


I see the log before sending the intent and no exception so the intent
should be brodcasted , but the intent is never cought by the intent
receiver as i never see anything in the log (i should see the name of
the intent).

Does anyone see what did i miss ?

Chris
--~--~---------~--~----~------------~-------~--~----~

2. Unable to resume activity:{...} Java.lang.Nullpointer exception

Hello.

This is my main class, which helps to displays data out of a database
in list format. It also handles a "ADD"and a "Delete" Button:


/**
 * A list view example where the
 * data for the list comes from an array of strings.
 */
public class TeaTime extends ListActivity {

        private static final int ACTIVITY_CREATE=0;
    private static final int ACTIVITY_EDIT=1;

    private TeaDB myDBHelper;
        private Cursor myTeaCursor;

        private static final int ADD_ID = Menu.FIRST;
        private static final int DELETE_ID = Menu.FIRST + 1;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
        myDBHelper = new TeaDB(this);
        myDBHelper.open();
        fillData();
        myDBHelper.close();
    }



    private String[] mStrings = {
            "Green Tea","Black Tea","Fruit Tea","Peppermint Tea"};

    /**
     * Get all Teas in an array to display on the screen
     */
    private void fillData() {
        // Get all of the rows from the database and create the item list
        myTeaCursor = myDBHelper.callUpAllTeas();
        startManagingCursor(myTeaCursor);

        // Create an array to specify the fields we want to display in
the list (only NAME)
        String[] from = new String[]{TeaDB.KEY_NAME};

        // and an array of the fields we want to bind those fields to
(in this case just text1)
        int[] to = new int[]{R.id.list};

        // Now create a simple cursor adapter and set it to display
 //       SimpleCursorAdapter tea =
  //                new SimpleCursorAdapter(this, R.layout.main,
myTeaCursor, from, to);
   //     setListAdapter(tea);

        ListAdapter test = new SimpleCursorAdapter(this,
R.layout.main, myTeaCursor, from, to);
        setListAdapter(test);
       // setListAdapter(new ArrayAdapter<String>(this,
        //android.R.layout.simple_list_item_1, from));


    }

    /**
     * Create the Menu (Add + Delete)
     */
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        menu.add(0, ADD_ID, R.string.menu_add);
        menu.add(0, DELETE_ID, R.string.menu_delete);
        return true;
    }

    /**
     * Activity Handler for the menu buttons (Add + Delete)
     */
    public boolean onMenuItemSelected(int featureId, Item item) {
        switch(item.getId()) {
        case ADD_ID:
            createTea();
            return true;
        case DELETE_ID:
            myDBHelper.deleteTea(4);
            //fillData();
            return true;
        }

        return super.onMenuItemSelected(featureId, item);
    }

    /**
     */
    private void createTea() {
        Intent i = new Intent(this, TeaEdit.class);
        startSubActivity(i, ACTIVITY_CREATE);
  }


If you press the "ADD" Button you come to the following activity which
allows you to add data. When I press the Button "CONFIRM" the saving
of the data in the database works, but also the error message
mentioned above shows up:


public class TeaEdit extends Activity {

        private EditText myNameText;
    private EditText myBrewTimeText;
    private Long myRowId;
    private TeaDB myDBHelper;

    @Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.tea_add);

        myNameText = (EditText) findViewById(R.id.name);
        myBrewTimeText = (EditText) findViewById(R.id.brewTime);

        Button confirmButton = (Button) findViewById(R.id.confirm);

        myDBHelper = new TeaDB(this);
        myDBHelper.open();

        confirmButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {

                myDBHelper.createTea(myNameText.getText().toString(),
Integer.valueOf(myBrewTimeText.getText().toString()));
                myDBHelper.close();
                setResult(RESULT_OK, null, null);
                finish();
            }

        });
    }
}


So if it helps, it would be great. Can you also please tell me where I
can find the "stack trace in logcat"?

Thank you
--~--~---------~--~----~------------~-------~--~----~

3. why the error?: List Views can't have unspecified size

4. File Sharing - App idea?

5. How validate Android OS

6. SLECTED_ALTERNATIVE & CALL action -> bundle null?

7. Not able to connect in emulator behind proxy