Pro Android with Kotlin



Yüklə 4,6 Kb.
Pdf görüntüsü
səhifə29/231
tarix29.11.2023
ölçüsü4,6 Kb.
#138831
1   ...   25   26   27   28   29   30   31   32   ...   231
@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 

element’s attributes:
 
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



Yüklə 4,6 Kb.

Dostları ilə paylaş:
1   ...   25   26   27   28   29   30   31   32   ...   231




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə