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

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

Sponsored Links

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

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);

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();
this.myIntentReceiver = new MyIntentReceiver();
this.registerReceiver(this.myIntentReceiver, this.myIntentFilter);

class MyIntentReceiver extends IntentReceiver {
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 ?


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


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;

    public void onCreate(Bundle icicle) {
        myDBHelper = new TeaDB(this);;

    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();

        // 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[]{};

        // 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(new ArrayAdapter<String>(this,
        //android.R.layout.simple_list_item_1, from));


     * Create the Menu (Add + Delete)
    public boolean onCreateOptionsMenu(Menu 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:
            return true;
        case DELETE_ID:
            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;

    protected void onCreate(Bundle icicle) {

        myNameText = (EditText) findViewById(;
        myBrewTimeText = (EditText) findViewById(;

        Button confirmButton = (Button) findViewById(;

        myDBHelper = new TeaDB(this);;

        confirmButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {

                setResult(RESULT_OK, null, null);


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