Persisting State of Components Follow
I'm trying to follow these instructions:
But I don't understand how this works, should I register my class somewhere? I've created a new class, implemented PersistentStateComponent with the @State annotation, but the getState and loadState methods are never fired.
If I put the implements in my ProjectComponent then the getState is executed automatically on startup, but I'm getting an Exception after returning "this":
Could not save project:
What I'm doing wrong?
Please sign in to leave a comment.
You should register your persistent class within the DI container. E.g. add the following for project-scoped settings to your plugin.xml:
Thanks for your reply Denis, but it didn't work.
I've added the <projectService> inside my <extensions defaultExtensionNs="com.intellij">
But the getState and loadState() are never called.
I don't understand how does this work.
How does the ide know that it must call the getState and loadState from my class? where I'm telling that?
Strangely if I implement PersistentStateComponent in my <projectConfigurable/> class, the getState and loadState methods are called (even without any <projectService>) but it doesn't work, it's throwing an error how I said in my first post.
Please can you post more details of how to implement this?
The requirements are as follows:
If you have done the following and the problem still persist you can attach a sample project, we'll take a look.
Project services are not instantiated unless someone requests them. If you simply declare a project service and never access it from any other code, it will never be created, and therefore the getState/loadState methods will never be called.
Well, I'm really lost, I don't know what to try, this is what I'm doing:
and inside my Form
what I'm doing wrong?
Your service is registered as a project service so you need to use ServiceManager.getInstance(project, aClass) method. The
ServiceManager.getInstance(aClass) method is used to obtain instances of application-level services.
"Develop with pleasure!"
Thanks ! it's working now !
ServiceManager.getInstance() seems depreciated and keeps giving me null pointer exception, any clue why?
The replacement for the deprecated APIs is documented in the javadoc comments: `Application.getService()` and `Project.getService()`. For the null pointer exception, we'd need to see the complete stacktrace in order to explain why it happens