Intent와 PendingIntent의 차이점
나는 몇몇 기사를 읽었고 둘 다 똑같은 일을하는 것 같고 서비스를 시작하는 것의 차이점이 무엇인지 궁금합니다.
Intent intent = new Intent(this, HelloService.class);
startService(intent);
또는 그렇게 :
Calendar cal = Calendar.getInstance();
Intent intent = new Intent(this, MyService.class);
PendingIntent pintent = PendingIntent.getService(this, 0, intent, 0);
AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 30*1000, pintent);
읽어 보았 듯이 서비스에서 START_STICKY 매개 변수를 반환하면이 두 가지가 동일한 작업을 수행합니다.
의지
Android 인 텐트는 인 텐트, 즉 한 구성 요소에서 애플리케이션 내부 또는 외부의 다른 구성 요소로 메시지를 전달하는 개체입니다. 인 텐트는 애플리케이션의 세 가지 핵심 구성 요소 인 활동, 서비스 및 BroadcastReceivers간에 메시지를 전달할 수 있습니다.
Intent 개체 인 의도 자체는 수동 데이터 구조입니다. 수행 할 작업에 대한 추상적 인 설명을 포함합니다.
예를 들어, 이메일 클라이언트를 시작하고 이메일을 보내야하는 활동이 있다고 가정합니다. 이를 위해 활동은 ACTION_SEND
적절한 선택기와 함께 작업이 포함 된 인 텐트를 Android 인 텐트 리졸버로 보냅니다 .
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
지정된 선택기는 사용자가 이메일 데이터를 보내는 방법을 선택할 수있는 적절한 인터페이스를 제공합니다.
명시 적 의도
// Explicit Intent by specifying its class name
Intent i = new Intent(this, TargetActivity.class);
i.putExtra("Key1", "ABC");
i.putExtra("Key2", "123");
// Starts TargetActivity
startActivity(i);
암시 적 의도
// Implicit Intent by specifying a URI
Intent i = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.example.com"));
// Starts Implicit Activity
startActivity(i);
보류중인 의도
PendingIntent는 외부 애플리케이션 (예 : NotificationManager, AlarmManager, 홈 화면 AppWidgetManager 또는 기타 타사 애플리케이션)에 제공하는 토큰으로, 외부 애플리케이션이 애플리케이션의 권한을 사용하여 미리 정의 된 코드를 실행할 수 있도록합니다.
PendingIntent를 다른 응용 프로그램에 부여하면 다른 응용 프로그램이 자신 인 것처럼 지정한 작업을 수행 할 수있는 권한을 부여하는 것입니다 (동일한 권한 및 ID 사용). 따라서 PendingIntent를 빌드하는 방법에주의해야합니다. 예를 들어, 제공하는 기본 Intent는 궁극적으로 다른 곳으로 전송되지 않도록 구성 요소 이름을 사용자 고유의 구성 요소 중 하나로 명시 적으로 설정해야합니다.
보류중인 의도의 예 : http://android-pending-intent.blogspot.in/
출처 : Android 인 텐트 및 Android 보류중인 인 텐트
도움이 되었기를 바랍니다.
PendingIntent
의 래퍼입니다 Intent
. 를 수신하는 외부 앱 은으로 래핑 된 PendingIntent
콘텐츠를 알지 못합니다 . 외국 앱의 임무는 일부 조건이 충족되면 소유자에게 의도를 되 돌리는 것입니다 (예 : 일정이있는 알람 또는 클릭으로 알림 ...). 조건은 소유자가 제공하지만 외국 앱에서 처리합니다 (예 : 알람, 알림).Intent
PendingIntent
외국 앱이 앱에 인 텐트를 보낸 경우 외국 앱이 인 텐트의 콘텐츠를 알고 있음을 의미합니다. 그리고 외국 앱이 의도를 보내기로 결정하면 앱이 일부 조건을 충족하기 위해 의도를 처리해야합니다 => 앱이 시스템의 성능 리소스를 얻습니다.
또 다른 간단한 차이점 :
정상적인 의도는 앱이 죽 자마자 죽습니다.
Pending intents never die. They will be alive as long as it's needed by alarm service, location service, or any other services.
Starting services regularly via AlarmManager
As with activities the Android system may terminate the process of a service at any time to save resources. For this reason you cannot simply use a TimerTask
in the service to ensure that it is executed on a regular basis.
So, for correct scheduling of the Service use the AlarmManager
class.
UPDATE:
So there is no actual difference between the two. But depending on whether you want to ensure the execution of the service or not, you can decide what to use as for the former there is no guarantee and for the later it is.
More info at AndroidServices.
Functionally, there is no difference.
The meaning of PendingIntent is that, you can handle it to other application that later can use it as if the other application was yourself. Here is the relevant explanation from the documentation:
By giving a PendingIntent to another application, you are granting it the right to perform the operation you have specified as if the other application was yourself (with the same permissions and identity). As such, you should be careful about how you build the PendingIntent: almost always, for example, the base Intent you supply should have the component name explicitly set to one of your own components, to ensure it is ultimately sent there and nowhere else.
A PendingIntent itself is simply a reference to a token maintained by the system describing the original data used to retrieve it.
So PendingIntent is just a reference to the data that represents the original Intent (that used to create the PendingIntent).
참고URL : https://stackoverflow.com/questions/24257247/differences-between-intent-and-pendingintent
'code' 카테고리의 다른 글
HTML5 Script 태그에 type =“javascript”가 필요합니까? (0) | 2020.09.01 |
---|---|
require : 'ngModel'의 의미는 무엇입니까? (0) | 2020.09.01 |
SQLAlchemy : 엔진, 연결 및 세션 차이 (0) | 2020.09.01 |
Visual Studio IDE에서 XSD를 사용한 XML 유효성 검사 (0) | 2020.09.01 |
C # / Linq : IEnumerable의 각 요소에 매핑 함수를 적용 하시겠습니까? (0) | 2020.09.01 |