Page 69 - 24JAM_Pintar_Pemrograman_Android__1-libre
P. 69

  24 JAM!! Pintar Pemrograman Android
            22:     public void onStart(Intent intent,int startId){
            23:            mp.start();
            24:     }
            25:
            26:     @Override
            27:     public void onDestroy(){
            28:            mp.stop();
            29:     }
            30:  }
            31:

                6.  Membuat activity ServiceSederhana.java

            1:  package com.serv.bg;
            2:
            3:  import android.app.Activity;
            4:  import android.content.Intent;
            5:  import android.os.Bundle;
            6:  import android.view.View;
            7:  import android.view.View.OnClickListener;
            8:  import android.widget.Button;
            9:
            10:  public class ServiceSederhana extends Activity implements
                OnClickListener {
            11:     Button startBtn,stopBtn;
            12:      /** Called when the activity is first created. */
            13:      @Override
            14:      public void onCreate(Bundle savedInstanceState) {
            15:          super.onCreate(savedInstanceState);
            16:          setContentView(R.layout.main);
            17:
            18:          startBtn=(Button)findViewById(R.id.startBtn);
            19:          stopBtn=(Button)findViewById(R.id.stopBtn);
            20:          startBtn.setOnClickListener(this);
            21:          stopBtn.setOnClickListener(this);
            22:
            23:      }
            24:     @Override
            25:     public void onClick(View v) {
            26:            switch(v.getId()){
            27:            case R.id.startBtn:
            28:                   startService(new
                Intent(this,MyService.class));
            29:                   break;
            30:            case R.id.stopBtn:
            31:                   stopService(new
                Intent(this,MyService.class));
            32:                   break;
            33:            }
            34:            // TODO Auto-generated method stub
            35:
            36:     }
            37:  }









                              Dapatkan materi terbaru di                   69
                                       www.omayib.com
   64   65   66   67   68   69   70   71   72   73   74