rahul
rahul

Reputation: 2906

Form application in android

I have a form application, in this application the user clicks on a Menu option(M1) to go to a form (Frm1). This is done using Intent. The form (Frm1) have two buttons, a back button and a submit button. When the user clicks the submit button the form is submitted, when the back button is clicked the user reaches the menu option(done using Intent). Now, When the user clicks the back button(he goes to M1) with a half filled form, he must be able to continue with the task when he returns back( to Frm1). My logic was to collect all the values in the form to a bundle and carry it along the way from Frm1 to M1 and vice versa. Is this a good approach, got any better idea?

Thanks in advance..!

Upvotes: 0

Views: 599

Answers (4)

mahesh kumar
mahesh kumar

Reputation: 11

You can use either Bundle or SharedPreferences. But better to go for SharedPreferences because Bundle is restricted to the session where as shared preferences is not.

Upvotes: 1

AlexKorovyansky
AlexKorovyansky

Reputation: 4943

If data entered in the form (Frm1) is used in your Menu Activity (M1), then obviously you should use bundles and send it between Activities.

Else it may be unwanted logic of working with forms data in Menu Activity.

Just imagine, that you will create new wonderful Activity before M1 in your app (dashboard or something similar to it). Now you have to pass your bundle to first activity, because else you will lose form's state, when user close Menu Activity. It's not good, anyway.

So, if you can encapsulate this logic in Form Activity, I recommend you to make it. You can use SharedPreferences or Singleton storage. If your form's data is strings, numbers and flags - SharedPreferences is easy, good and safe solution.

Upvotes: 1

james
james

Reputation: 26271

Another option would be to save the form data in the SharedPreferences. The difference between saving it in a bundle and this is that the data will persist upon an app shutdown. Saving the data into a bundle will only last during the application's lifecycle

Upvotes: 0

RivieraKid
RivieraKid

Reputation: 5961

Using a bundle is exactly the right way to do this, though if the user has pressed the back button, are you sure they want to keep the data they entered? You will have to provide some way to clear the form.

Upvotes: 1

Related Questions