Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing data between activity and stepper fragments #7

Open
lodogg opened this issue Mar 14, 2016 · 8 comments
Open

Passing data between activity and stepper fragments #7

lodogg opened this issue Mar 14, 2016 · 8 comments

Comments

@lodogg
Copy link

lodogg commented Mar 14, 2016

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.

@shivasurya
Copy link
Owner

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.

@Isabellle
Copy link

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.

@shivasurya
Copy link
Owner

shivasurya commented May 11, 2016

@Isabellle thanks for mentioning the issue :)
added bundle support and it's being tested shivasurya/stepperTest@5e4ba5a
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.

@Isabellle
Copy link

Sounds great, will wait until this great update is available.
Thanks for all the work you've done.

@shivasurya
Copy link
Owner

Hello,
Rolling out new features and bug fix. Especially bundle to communicate between fragments have been implemented. So please stay tuned for next update

@lecrane54
Copy link

Can you please update this library? i really need the addBundle method.

@Osmandiyaka
Copy link

please can you please update the bundle

@peter-wachira
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants