SaveState
SaveState copied to clipboard
Bug: no way to use "private" for the fields
classpath "io.github.prototypez:save-state:0.2.3"
Example:
class MainActivity : AppCompatActivity() {
@AutoRestore
private var someInt: Long = 0L
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
if (savedInstanceState == null)
someInt = System.currentTimeMillis()
Log.d("AppLog", "someInt:$someInt")
}
}
Error that I get:
C:\Users\User\Desktop\SaveStateSample\app\build\generated\source\kapt\debug\com\lb\savestatesample\MainActivityAutoSaveState.java:7: error: someInt has private access in MainActivity
outState.putLong("someInt", instance.someInt);
^
C:\Users\User\Desktop\SaveStateSample\app\build\generated\source\kapt\debug\com\lb\savestatesample\MainActivityAutoSaveState.java:11: error: someInt has private access in MainActivity
instance.someInt = savedInstanceState.getLong("someInt");
^
Sample: SaveStateSample.zip
Currently private fields are not support because my implementation relies on apt, changing the modifier to default or protected is a workaround
@PrototypeZ Can you please consider changing it so that it would work? It's quite a harsh requirement to force us to have such fields are non-private...
I'm refactering my plugin by using asm and private fields will be supported soon.
@PrototypeZ "asm" ? Assembly language?! You went this far? :)
Sorry acturally i mean using the ASM framework to manipulate byte codes inside the Transform Api...
I don't know what this is, but sounds complex too. Can it also generate java code from byte code?
@AndroidDeveloperLB yes, it's similar to annotation processor, but it can change class byte codes we write at compile time while annotation processor can only add new classes. :)
Wow cool! Sadly I never created anything that handles annotations. To me it seems like magic.
Thank you sir, actually I've read a lot of your answers on StackOverflow which helped me a lot, thank you so much. I'm so glad that you leave a comment on my repo. I'm not a native speaker so I'm not sure if i express my feelings properly, just let you know that I'm one of your fans. :)
@PrototypeZ Really? Thank you. Do you know perhaps of a nice tutorial (video is great too) of creating new annotations? Maybe it's time to play with this a bit. On both Java and Kotlin.
@AndroidDeveloperLB Hey I just found this post, I hope it helps. :)
@PrototypeZ I don't understand what it is. Sorry.
hey, don't worry. I'm not sure whether I misunderstand your intention, maybe it's me who needs to say sorry...please send me an email at [email protected] and I can explain anything which you are confused with.
@PrototypeZ Doesn't matter. Forget it.