开发者

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 i开发者_如何转开发t along the way from Frm1 to M1 and vice versa. Is this a good approach, got any better idea?

Thanks in advance..!


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.


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜