Pro Android with Kotlin
Download 5.42 Mb. Pdf ko'rish
|
@de android telegram Pro Android with Kotlin Developing Modern Mobile
16
CHAPTER 3: Activities The corresponding code to address this intent filter and actually launch the activity now looks like this: val intent = Intent() intent.action = "com.example.myapp.ExampleActivity.START_ME" startActivity(intent) The flag exported="false" must be set for calls from other apps. The category specification android.intent.category.DEFAULT inside the filter takes care of the activity being launchable even with no category set in the launching code. In the previous example, we used an explicit intent to call an activity. We precisely told Android which activity to call, and we even expect there to be precisely one activity, which gets addressed this way through its intent filter. The other type of intent is called an implicit intent, and what it does, contrary to calling precisely one activity, is tell the system what we actually want to do without specifying which app or which component to use. Such implicit calls, for example, look like this: val intent = Intent(Intent.ACTION_SEND) intent.type = "text/plain" intent.putExtra(Intent.EXTRA_TEXT, "Give me a Quote") startActivity(intent) This snippet calls an activity that is able to handle Intent.ACTION_SEND actions, receive texts in the MIME type text/plain, and pass over the text “Give me a quote.” The Android OS will then present the user with a list of activities from this or other apps that are capable of receiving this kind of intent. Activities can have data associated with them. Just use one of the overloaded putExtra(...) methods of the intent class. Activities and Tasks What actually happens with a launched activity concerning the task stack gets determined by the attributes, listed here, as given in the taskAffinity launchMode allowTaskReparenting clearTaskOnLaunch alwaysRetainTaskState finishOnTaskLaunch and by the intent calling flags, listed here: FLAG_ACTIVITY_NEW_TASK FLAG_ACTIVITY_CLEAR_TOP FLAG_ACTIVITY_SINGLE_TOP |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling