부팅시 브로드캐스트로 service실행
* StartReceiver.class
public class StartReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Intent i = new Intent(context, ServiceClass.class);
context.startService(i);
}
}
}
* MianActivity.class
//폰번호 전달
Intent intent = new Intent(MainActivity.this, ServiceClass.class);
intent.putExtra("phone", inputnumber);
startService(intent);
*ServiceClass.class
@Override
public int onStartCommand(Intent intent, int flags, int startId){
Log.i(TAG," +++ onStartCommand Service +++");
super.onStartCommand(intent, flags, startId);
inputnumber = intent.getStringExtra("phone");
Log.i(TAG,"인텐드로 넘어 온 값 보이도 : "+ inputnumber);
return Service.START_REDELIVER_INTENT; //전화 번호 값 유지하기 위해서
}
처음 앱 실행후 서비스에서는 휴대폰번호가 잘 오는데
스마트폰 재부팅시에는 값을 가져오지 못합니다. 어떻게 해야하는지 좀 알려주세요 부탁드립니다.
아이디어가 떠오르지 않네요ㅠㅠ