public void doClick(View v) { switch (v.getId()) { case R.id.start: intent1 = new Intent(MainActivity.this, MyStartService.class); startService(intent1); break; case R.id.stop: stopService(intent1); break; } }
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; }
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
public class MyStartService extends Service { @Override public void onCreate() { // TODO Auto-generated method stub Log.i("info", "Service--onCreate()"); super.onCreate(); }
@Override public int onStartCommand(Intent intent, int flags, int startId) { // TODO Auto-generated method stub Log.i("info", "Service--onStartCommand()"); return super.onStartCommand(intent, flags, startId); }
@Override public void onDestroy() { // TODO Auto-generated method stub Log.i("info", "Service--onDestroy()"); super.onDestroy(); }
@Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub Log.i("info", "Service--onBind()"); return null; }
public void doClick(View v) { switch (v.getId()) { case R.id.start: intent1 = new Intent(MainActivity.this, MyStartService.class); startService(intent1); break;
case R.id.stop: stopService(intent1); break;
case R.id.play: service.Play(); break;
case R.id.pause: service.Pause(); break;
case R.id.pervious: service.Pervious(); break;
case R.id.next: service.next(); break;
case R.id.bind: intent2 = new Intent(MainActivity.this, MyBindService.class); bindService(intent2, conn, Service.BIND_AUTO_CREATE); break;
case R.id.unbind: unbindService(conn); break; } }
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; }
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
public void doClick(View v) { switch (v.getId()) { case R.id.start: intent1 = new Intent(MainActivity.this, MyStartService.class); startService(intent1); break;
case R.id.stop: stopService(intent1); break;
case R.id.play: service.Play(); break;
case R.id.pause: service.Pause(); break;
case R.id.pervious: service.Pervious(); break;
case R.id.next: service.next(); break;
case R.id.bind: intent2 = new Intent(MainActivity.this, MyBindService.class); startService(intent2); bindService(intent2, conn, Service.BIND_AUTO_CREATE); break;
case R.id.unbind: unbindService(conn); break; } } @Override protected void onDestroy() { // TODO Auto-generated method stub stopService(intent2); unbindService(conn); super.onDestroy(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; }
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }