Issue
I have a variable from the Application class. I want to change the value of the variable (which originates from the Application class) from another activity. Right now, I can only create an instance of the variable, and then change the value of the instance, which defeats the whole purpose of creating the variable from Application class (so it can be used throughout all activities in project)
Here is the variable. It is a long, and represents the number of activities that have passed by:
I am trying to change the value of numberOfActivities from every activity by trying to do something like this:
((activityCount) getApplicationContext()).numberOfActivities++;
As you can see here, I am only changing an instance of it. When I try to access the variable later, the value is 0. This shouldn't be the case, as I have declared it static. The popup comes up when I hover over the line saying static member accessed via instance reference. How can I fully change the value of the variable from a separate activity?
Thank you so much, and if you need any more information, feel free to let me know. Any feedback is appreciated.
Thanks!
Solution
I figured it out! I just had to set it to System.currentTimeMillis() in the myApplication class itself. Like this:
Although this is a great workaround, I would love to see a way to access and change it in another class itself.
Answered By - Ruchir Baronia
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.