Skip to content

Instantly share code, notes, and snippets.

@sorah
Created September 12, 2011 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sorah/2d853e4841c5828f1e3a to your computer and use it in GitHub Desktop.
Save sorah/2d853e4841c5828f1e3a to your computer and use it in GitHub Desktop.
Google Developer Day 2011 Tokyo / DevQuiz: Android
package org.ajunk.android.gdd2011devquiz;
import android.app.Activity;
import android.os.Bundle;
import android.content.ComponentName;
import android.app.AlertDialog;
import android.os.IBinder;
import android.content.ServiceConnection;
import android.content.Intent;
import com.google.android.apps.gddquiz.IQuizService;
public class DevQuiz extends Activity
{
private IQuizService service_if;
private AlertDialog.Builder alert;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
alert = new AlertDialog.Builder(this);
Intent intent = new Intent(IQuizService.class.getName());
bindService(intent, service_conn, BIND_AUTO_CREATE);
}
@Override
public void onDestroy() {
super.onDestroy();
unbindService(service_conn);
}
private ServiceConnection service_conn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
service_if = IQuizService.Stub.asInterface(service);
alert.setTitle("code");
try {
alert.setMessage(service_if.getCode());
} catch(android.os.RemoteException e) {}
alert.setPositiveButton("OK",null);
alert.show();
}
@Override
public void onServiceDisconnected(ComponentName name) {
service_if = null;
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment