materialsteppers
materialsteppers copied to clipboard
Passing data between activity and stepper fragments
Hi, I have an issue that I can't solve. In my app, I'll use the stepper to perform a configuration of an already connected bluetooth device. I need to pass the bluetooth device connectivity information from the main activity to the stepper fragments in order to send command and receive information over bluetooth.
Starting from main, my idea is to use do this:
BluetoothDevice mBtDevice
final Intent mIntent = new Intent(MainActivity.this, CalibrationActivity.class);
mIntent.putExtra("BluetoothDevice", mBtDevice);
startActivity(mIntent);
so I will "receive" the bluetooth device in the activity that extend progressMobileStepper. At this point every thing is all right, in "mBtDevice" I have all the information I need. This is what I have done so far:
public class CalibrationActivity extends progressMobileStepper {
List<Class> stepperFragmentList = new ArrayList<>();
BluetoothDevice mBtDevice;
@Override
public List<Class> init() {
Bundle data = getIntent().getExtras();
mBtDevice= data.getParcelable("BluetoothDevice");
Fragment fragment = new Fragment();
Bundle bundle = new Bundle();
bundle.putParcelable("toFragmentBtDevice", mBtDevice);
fragment.setArguments(bundle);
stepperFragmentList.add(CalibrationStep1Fragment.class);
return stepperFragmentList;
}
@Override
public void onStepperCompleted() {
//nothing at the moment...
}
The problem is in the "CalibrationStep1Fragment". This is the code:
public class CalibrationStep1Fragment extends stepperFragment {
BluetoothDevice mBtDevice;
@Override
public boolean onNextButtonHandler() {
return true;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
Bundle bundle = getArguments(); // thsi is null
mBtDevice= bundle.getParcelable("toFragmentBtDevice");
return inflater.inflate(
R.layout.stepper_step1, container, false);
}
}
at this point bundle is null ( Bundle bundle = getArguments(); )
Please tell me if something is not clear and I'll try to give more information.
till now this library is not supported for passing bundle to pass data between fragments - but surely you can save data in sharedpreference in each fragment and process/communicate between fragments.
i'll look into the way to use bundle for communication between fragments in next updats/versions.
And the above code you've tried isn't way - you must pass the class names as list and the inbuilt library does the work of creating new fragment instance and destroying it dynamically - i have implemented this because it drastically reduces the memory consumption of fragments in heap memory. - assume if you have 20+ fragment objects at once - it may leak memory/ cause overhead.
hope you can understand.
This is indeed the only weakness of this library. I understand that I might work though? I mean passing bundles or not at all? Looking forward to reading you.
@Isabellle thanks for mentioning the issue :) added bundle support and it's being tested https://github.com/shivasurya/stepperTest/commit/5e4ba5ad7a7d0750bb7f162c044c09f3503c27d7 and it'll be added in next version - i'm making it sure it doesn't make problem at any circumstance such as orientation changes,resume,pause operations.
Sounds great, will wait until this great update is available. Thanks for all the work you've done.
Hello, Rolling out new features and bug fix. Especially bundle to communicate between fragments have been implemented. So please stay tuned for next update
Can you please update this library? i really need the addBundle method.
please can you please update the bundle
Was this issue ever fixed? It seems it's not possible to pass data using shared preferences in the fragments as well. Kindly reach out on whether this is possible