Skip to content

Passing data between activity and stepper fragments #7

Description

@lodogg

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions