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

need some more tutorials #3

Open
jjhesk opened this issue Feb 26, 2015 · 6 comments
Open

need some more tutorials #3

jjhesk opened this issue Feb 26, 2015 · 6 comments

Comments

@jjhesk
Copy link

jjhesk commented Feb 26, 2015

in some reason i am not totally understand

  @Retain(permanent = true)
  @Parameter(key = EXTRA_VALUE)
  @Retain

these meaning.. what are the differences here.

@dmfs
Copy link
Owner

dmfs commented Feb 26, 2015

@retain

This retains the annotated value over destroy/create cycles with a saved instance state (i.e. when the device is rotated or when the app is "shut down" temporarily because another app has come to the foreground).

@retain(permanent = true)

This retains the value of the annotated field permanently. It means the value is stored in the shared preferences when an activity or fragment is destroyed and it's loaded from the shared preferences when the activity or fragment is created. This is useful to restore the last value of this field after the activity or fragment has been closed completely. Of course it also covers the previous case.

This can be done per instance. So if you have multiple instances of the same fragment (i.e. like in a pager) you can add the parameter instanceNSField = "mInstance" where mInstance is a field that holds an identifier for the current instance. The only requirement is that mInstance can be converted to a string, because it will become part of the key.

@parameter(key = EXTRA_VALUE)

This initializes the annotated field with the value of an extra (in case of an activity) or the argument (in case of a fragment) of the same key. That happens when the activity or fragment are created for the first time (i.e. without saved instance state). but not when it's recreated with a saved instance state (i.e. when the device is rotated).

Let me know if you have any other questions. Or check out our task app or color picker. You can find more examples in there.

@dmfs
Copy link
Owner

dmfs commented Feb 26, 2015

Also check out the example application and monitor the values. You'll see that some are retained when you close the app and others will only be retained when you rotate the device.

@jjhesk
Copy link
Author

jjhesk commented Feb 26, 2015

I think I have the basic grasp of the idea on how to use it now.

@jjhesk jjhesk closed this as completed Feb 26, 2015
@dmfs
Copy link
Owner

dmfs commented Feb 26, 2015

Great! If you any feature requests, please don't hesitate to tell us.

@jjhesk jjhesk reopened this Feb 26, 2015
@jjhesk
Copy link
Author

jjhesk commented Feb 26, 2015

How does it allow combination of extra parameters take control in the annotation such as @Retain(permanent = true, classNS = "DemoActivity") ?

@dmfs
Copy link
Owner

dmfs commented Feb 27, 2015

You mean what the effect of these extra parameter is?
Most of them have an effect on the key that's used to store the value in the instance state Bundle or the shared preferences. By default the actual class name will be used, but that might cause problems when you use ProGuard or similar tools to reduce the binary size or obfuscate the code, because they may change the class and package name.
I suggest you send me an email to marten at dmfs.org for further questions.

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

No branches or pull requests

2 participants