안드로이드 서비스에 대한 많은 예제와 튜토리얼은 bound services입니다.하지만 바인딩되지 않은 서비스를 만들고 바인딩을 전혀 처리하지 않으려면 어떻게해야합니까?Android에서 언 바운드 서비스는 어떻게 만듭니 까?
이 downvoting하기 전에 왜 answering your own questions is a good thing에 읽어주십시오 가능성 downvoters에
참고. 이 모든 서비스가 수행
public class RecordingService extends Service {
private int NOTIFICATION = 1; // Unique identifier for our notification
public static boolean isRunning = false;
public static RecordingService instance = null;
private NotificationManager notificationManager = null;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate(){
instance = this;
isRunning = true;
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId){
// The PendingIntent to launch our activity if the user selects this notification
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
// Set the info for the views that show in the notification panel.
Notification notification = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher) // the status icon
.setTicker("Service running...") // the status text
.setWhen(System.currentTimeMillis()) // the time stamp
.setContentTitle("My App") // the label of the entry
.setContentText("Service running...") // the content of the entry
.setContentIntent(contentIntent) // the intent to send when the entry is clicked
.setOngoing(true) // make persistent (disable swipe-away)
.build();
// Start service in foreground mode
startForeground(NOTIFICATION, notification);
return START_STICKY;
}
@Override
public void onDestroy(){
isRunning = false;
instance = null;
notificationManager.cancel(NOTIFICATION); // Remove notification
super.onDestroy();
}
public void doSomething(){
Toast.makeText(getApplicationContext(), "Doing stuff from service...", Toast.LENGTH_SHORT).show();
}
}
은 다음과 같습니다
<application ...>
...
<service
android:name=".RecordingService"
android:exported="false">
</application>
그런 다음 우리가 실제 서비스 클래스를 만들 :
당신은 분 이내에 자신의 게시물을 대답 했 ...!? – Shaishav
@Shaishav 예 했어요. 사실 "Ask a question"페이지의 하단에있는 확인란을 사용하여 게시하기 전에 답변했습니다. Stackoverflow에서 간단한 언 바운드 서비스를 만드는 방법에 대한 명확하고 완전한 데모를 찾을 수 없으므로 지금 어떻게 해야할지를 알기 시작했습니다. [자신의 질문에 대한 답변을 보려면 여기를 클릭하십시오.] – BadCash
차갑다. 정보 주셔서 감사합니다. – Shaishav