Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * このクラスを実行するには、AndroidManifest.xmlに以下を記入してください。
- * <application
- * <service android:name="RecordVoiceService" />
- * </application>
- *
- * 開始するには、
- * startService(new Intent(getBaseContext(), MyService.class));
- * 停止させるには、
- * stopService(new Intent(getBaseContext(), MyService.class));
- * で呼び出します。
- *
- * stopSelf()でService自身が停止することもできます。
- *
- * SerViceはメインスレッドで実行されます。
- * CPU を集中的に使ったり、ブロック操作を行ったりするような場合は別スレッドで実行してください。
- */
- import android.app.Service;
- import android.content.Intent;
- import android.os.IBinder;
- import android.support.annotation.Nullable;
- import android.util.Log;
- public class MyService extends Service {
- @Nullable
- @Override
- public IBinder onBind(Intent intent) {
- return null;
- }
- @Override
- public void onCreate() {
- super.onCreate();
- Log.d("LifeCycle", "onCreate");
- }
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- startRecordVoice();
- Log.d("LifeCycle", "onStartCommand");
- return super.onStartCommand(intent, flags, startId);
- }
- @Override
- public void onDestroy() {
- super.onDestroy();
- Log.d("LifeCycle", "onDestroy");
- }
- }
Add Comment
Please, Sign In to add comment