mirror of
https://github.com/balkian/Carrousel-Android.git
synced 2024-12-22 21:18:13 +00:00
I4: Conectar la actividad con el servicio
This commit is contained in:
parent
c45887f26e
commit
98e7c5208b
@ -1,13 +1,34 @@
|
|||||||
package com.onirica.carrousel;
|
package com.onirica.carrousel;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.ServiceConnection;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.IBinder;
|
||||||
|
|
||||||
public class Configuration extends Activity {
|
public class Configuration extends Activity {
|
||||||
|
private Results mResults;
|
||||||
/** Called when the activity is first created. */
|
/** Called when the activity is first created. */
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.main);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,14 +5,20 @@ import java.util.TimerTask;
|
|||||||
|
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Binder;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
|
||||||
public class Results extends Service {
|
public class Results extends Service {
|
||||||
|
private final IBinder mBinder = new LocalBinder();
|
||||||
|
|
||||||
|
public class LocalBinder extends Binder {
|
||||||
|
Results getService() {
|
||||||
|
return Results.this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent arg0) {
|
public IBinder onBind(Intent arg0) {
|
||||||
// TODO Auto-generated method stub
|
return mBinder;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
|
Loading…
Reference in New Issue
Block a user