과 같이 종료에 대한 방송을 수신하는 서비스 만들기 : 당신의 AndroidManifest.xml
에서
public class MyAppShutdown extends BroadcastReceiver{
private static final String TAG = "MyAppShutdown";
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.v(TAG, "onReceive - ++ ENTER ++");
if (intent != null && intent.getAction().equals(Intent.ACTION_SHUTDOWN)){
Log.v(TAG, "onReceive - ***] SHUTDOWN [***");
// perhaps send a broadcast to your app via intent to perform a log out.
Intent intent = new Intent();
intent.addAction("intent.myapp.action.shutdown");
sendBroadcast(intent);
}
Log.v(TAG, "onReceive - ++ LEAVE ++");
}
}
는 <application>
태그 내에서 다음이 단편을 포함 : 앱의 활동에서
<receiver android:name=".MyAppShutdown">
<intent-filter>
<action android:name="android.intent.action.SHUTDOWN"/>
</intent-filter>
</receiver>
이 등록 인 텐트를위한 적절한 필터를 갖춘 브로드 캐스트 수신기 :
public class myApp extends Activity{
private myAppBroadcastRcvr myAppRcvr = new myAppBroadcastRcvr();
@Override
public void onCreate(Bundle savedInstanceState){
IntentFilter filter = new IntentFilter();
filter.addAction("intent.myapp.action.shutdown");
registerReceiver(myAppRcvr, filter);
}
// Perhaps you have this
private void LogOff(){
}
class myAppBroadcastRcvr extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent){
if (intent.getAction().equals("intent.myapp.action.shutdown")){
LogOff();
}
}
}
}
Oklet은 LogOff()를 호출한다고 가정합니다. 플랫폼 네트워크 라디오가 꺼져 있기 때문에 데이터를 보낼 수 없습니다 !!! – NitZRobotKoder
예! 나는 당신의 질문을 다시 읽은 후 다소 실감했다. 놀랐다. 안드로이드가 주변을 바꿨다고 믿을 수 없다. 라디오가 마지막으로 꺼져 있다고 생각했을 것이다. ... – t0mm13b
thats Ok !! 그래, 왜 행동이 바뀌 었는지 이상해 !! – NitZRobotKoder