From 98e7c5208b792c3cbb68169c92c640fb6e52e3c5 Mon Sep 17 00:00:00 2001 From: Fernando Herrera Date: Wed, 9 Mar 2011 23:14:57 +0100 Subject: [PATCH] I4: Conectar la actividad con el servicio --- src/com/onirica/carrousel/Configuration.java | 21 ++++++++++++++++++++ src/com/onirica/carrousel/Results.java | 10 ++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/com/onirica/carrousel/Configuration.java b/src/com/onirica/carrousel/Configuration.java index 72b7384..83ced7f 100644 --- a/src/com/onirica/carrousel/Configuration.java +++ b/src/com/onirica/carrousel/Configuration.java @@ -1,13 +1,34 @@ package com.onirica.carrousel; import android.app.Activity; +import android.content.ComponentName; +import android.content.Intent; +import android.content.ServiceConnection; import android.os.Bundle; +import android.os.IBinder; public class Configuration extends Activity { + private Results mResults; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); + Intent intent = new Intent(getBaseContext(), Results.class); + startService(intent); + ServiceConnection conn = new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName className, IBinder service) { + mResults = ((Results.LocalBinder)service).getService(); + + } + @Override + public void onServiceDisconnected(ComponentName className) { + mResults = null; + } + + + }; + bindService(intent, conn, BIND_AUTO_CREATE); } } \ No newline at end of file diff --git a/src/com/onirica/carrousel/Results.java b/src/com/onirica/carrousel/Results.java index f5518a2..ebab264 100644 --- a/src/com/onirica/carrousel/Results.java +++ b/src/com/onirica/carrousel/Results.java @@ -5,14 +5,20 @@ import java.util.TimerTask; import android.app.Service; import android.content.Intent; +import android.os.Binder; import android.os.IBinder; public class Results extends Service { + private final IBinder mBinder = new LocalBinder(); + public class LocalBinder extends Binder { + Results getService() { + return Results.this; + } + } @Override public IBinder onBind(Intent arg0) { - // TODO Auto-generated method stub - return null; + return mBinder; } @Override public void onCreate() {