opklessons.blogg.se

Android studio fragment activity for result
Android studio fragment activity for result













android studio fragment activity for result

So, when the onActivityResult is triggered, you can capture the result on the host activity. StartActivityForResult(this, intent, ((requestIndex + 1) << 16) + (requestCode & 0xffff), options) Note how the request Code is overriden ((requestIndex + 1) << 16) + (requestCode & 0xffff) Since the Android Support Library is being used for fragment support in earlier Android versions, the activity also needs to be changed to subclass from. This happens because the host of a Fragment is a FragmentActivity and not a simple Activity // From FragmentActivity Building layouts Step 0: Create the app base code Step 1: Diagram the layout Step 2: Implement the title row Step 3: Implement the button row Step 4.

android studio fragment activity for result android studio fragment activity for result

However, if you call that method from inside a Fragment, Android will internally change the request code (so it can automatically track the fragment which triggered the request). When you start an activity, you have to set a requestCode: // Note the request code: 0 StartActivityForResult is deprecated Introduction Android has been on the edge of evolution for a while recently, with updates to androidx.activity:activity-ktx to 1.2.0. So, each fragment can track the result properly: The activity result makes sense only for the fragment which requested it. You must implement the onActityResult for every Fragment which started an activity via startActivityForResult.















Android studio fragment activity for result