Pro Android with Kotlin


Download 5.42 Mb.
Pdf ko'rish
bet30/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   26   27   28   29   30   31   32   33   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile

17
CHAPTER 3: Activities
You can specify Intent.flags = Intent., where  is one from the list. In case 
the activity attributes and caller flags contradict, the caller flags win.
Activities Returning Data
If you start an activity by using this:
startActivityForResult(intent:Intent, requestCode:Int)
it means you expect the called activity to give something back while it returns. The construct 
you use in the called activity reads as follows:
val intent = Intent()
intent.putExtra(...)
intent.putExtra(...)
setResult(Activity.RESULT_OK, intent)
finish()
where inside the .putExtra(...) method calls you can add whatever data is to be returned 
from the activity. You can, for example, add these lines to the onBackPressed() event handler 
method.
For setResult()’s first argument, you can use any of the following:

Activity.RESULT_OK if you want to tell the caller the called activity 
successfully finished its job.

Activity.RESULT_CANCELED if you want to tell the caller the called activity 
did not successfully finish its job. You still can put extra information via 
.putExtra(...) to specify what went wrong.

Activity.RESULT_FIRST_USER + N, with N being any number from 0, 1, 2, 
..., for any custom result code you want to define. There is practically no 
limit for N (the maximum value reads 2
31
− 1).
Note that you need to take care of also handling back-press events if you have a toolbar. 
One possibility is to add to the onCreate() method lines as follows:
setSupportActionBar(toolbar)
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
// The navigation button from the toolbar does not
// do the same as the BACK button, more precisely
// it does not call the onBackPressed() method.
// We add a listener to do it ourselves
toolbar.setNavigationOnClickListener { onBackPressed() }



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   26   27   28   29   30   31   32   33   ...   223




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling