0 Replies - 1958 Views - Last Post: 16 September 2012 - 12:46 AM

#1 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Update widget from a service that the Main activity needs to bind to

Posted 16 September 2012 - 12:46 AM

Hi. Has been a while now, but now I've bite of more then i can thew.

So, this is the case.
I'm working on a music app(not some android media 101 ), and I've put the musicplayer in a service to allow the user to minimize the app and still continue listening to music. But, i need to update my widget and listen to Click from it that should control the music. So, how do i do this? I was thinking that i could put the class the extends AppWidgetProvider inside the class that extends service and then they could call each other without needing to create a new instance of each other each time, but i was wrong.

I'm not sure what code to post, but here is the part where i connect to the service in the main activity
private ServiceConnection mConnection = new ServiceConnection() {
	        public void onServiceConnected(ComponentName className, IBinder serviceBinder) {
	            Log.d("MainActivity","service connected");
	            Log.d("Service", "Connected");
	            //bound with Service. get Service instance
	            GMServiceBinder binder = (GMServiceBinder) serviceBinder;
	            mService = binder.getService();
	 
	            //send this instance to the service, so it can make callbacks on this instance as a client
	            mService.setClient(GrooveMobileActivity.this);
	            mBound = true;
	 
	 
	        }
	 
	        public void onServiceDisconnected(ComponentName arg0) {
	            mBound = false;
	        }
	    };



and here is my extended AppWidgetProvider
	public class GMWidget extends AppWidgetProvider {
		String LOG = "GMWidget";
		@Override
		  public void onUpdate(Context context, AppWidgetManager appWidgetManager,
		      int[] appWidgetIds) {
			Log.w(LOG, "onUpdate method called");
		    // Get all ids
		    ComponentName thisWidget = new ComponentName(context,
		    		GMWidget.class);
		    int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
		   // updateWidget(allWidgetIds);
			
		}

	}



Hope someone can help me.
Thanks in advance :)

This post has been edited by EndLessMind: 16 September 2012 - 02:30 AM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1