-
-
Save sorah/2d853e4841c5828f1e3a to your computer and use it in GitHub Desktop.
Google Developer Day 2011 Tokyo / DevQuiz: Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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