Guest User

Untitled

a guest
Nov 20th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. /*
  2. * このクラスを実行するには、AndroidManifest.xmlに以下を記入してください。
  3. * <application
  4. * <service android:name="RecordVoiceService" />
  5. * </application>
  6. *
  7. * 開始するには、
  8. * startService(new Intent(getBaseContext(), MyService.class));
  9. * 停止させるには、
  10. * stopService(new Intent(getBaseContext(), MyService.class));
  11. * で呼び出します。
  12. *
  13. * stopSelf()でService自身が停止することもできます。
  14. *
  15. * SerViceはメインスレッドで実行されます。
  16. * CPU を集中的に使ったり、ブロック操作を行ったりするような場合は別スレッドで実行してください。
  17. */
  18. import android.app.Service;
  19. import android.content.Intent;
  20. import android.os.IBinder;
  21. import android.support.annotation.Nullable;
  22. import android.util.Log;
  23.  
  24. public class MyService extends Service {
  25.  
  26. @Nullable
  27. @Override
  28. public IBinder onBind(Intent intent) {
  29. return null;
  30. }
  31.  
  32. @Override
  33. public void onCreate() {
  34. super.onCreate();
  35. Log.d("LifeCycle", "onCreate");
  36. }
  37.  
  38. @Override
  39. public int onStartCommand(Intent intent, int flags, int startId) {
  40. startRecordVoice();
  41. Log.d("LifeCycle", "onStartCommand");
  42. return super.onStartCommand(intent, flags, startId);
  43. }
  44.  
  45. @Override
  46. public void onDestroy() {
  47. super.onDestroy();
  48. Log.d("LifeCycle", "onDestroy");
  49. }
  50. }
Add Comment
Please, Sign In to add comment