Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
robert30
Posts: 191
Registered: ‎04-02-2013
My Device: BlackBerry Bold 9900
My Carrier: developer

Re: Problem in persistent value

Yes i have created the key as you are saying package name+ key 1 and converted into long.

 

 

On screen1 i am doing like this:

 

 

PersistentObject object = PersistentStore.getPersistentObject(key1);
System.out.println("value in object is :  "+object.getContents());
if(object.getContents()==null)
{
boolean flag= true;
PersistentObject flagObject;
flagObject=PersistentStore.getPersistentObject(screenKey);
flagObject.setContents(new Boolean(flag));
flagObject.commit();
System.out.println("Value is : "+flag);
System.out.println("If value is true..Then move to SlidingScreen!!");
UiApplication.getUiApplication().pushScreen(new SlidingScreen(Splash1.this));

}

else if(object.getContents()!= null)
{
boolean val = ((Boolean) object.getContents()).booleanValue();
if(val== true)
{
System.out.println("If value is true..Then move to SlidingScreen!!");
UiApplication.getUiApplication().pushScreen(new SlidingScreen(Splash1.this));
}

else
{
System.out.println("If value is flase..Then move to OverlayScreen!!");
UiApplication.getUiApplication().pushScreen(new OverlayScreen(Splash1.this));
}
}
}

 

 

and on Screen 2 i am changing the value of flag in persistent as: 

 

boolean flag= false;
PersistentObject obj = PersistentStore.getPersistentObject(key1);

obj.setContents(new Boolean(flag));
obj.commit();

boolean val = ((Boolean)obj.getContents()).booleanValue();
System.out.println("Value i s: "+val);

 

 

The problem is initially i have nothing in persistent object so the value of flag is true, the controls goes to Sliding screen ,now  in Screen2 i have changed the value of flag as false.

If i close the application and again open it i directly move to overlayScreen as the value of flag is false.

 

Now if i debug my application again even then the value of flag is false so i move to overlay screen.

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem in persistent value

[ Edited ]

Sorry I have not really looked at your problem, just I am struggling to understand your code.

 

Can I suggest you review your code and try to make it simpler and make the names more meaningful.  For example:

PersistentObject object = PersistentStore.getPersistentObject(key1);
System.out.println("value in object is :  "+object.getContents());
if(object.getContents()==null)

 

What does key1 mean?  Why is this key different to the value you use later (screenKey)?  How useful is calling an Object 'object' - it tells the reader nothing about it.  What is this object used for?  Why invoke object.getContents() repeatedly when you can do it once? 

 

I'm not saying the following is correct, but if you coded like this, then it would be more obvious to you and other readers of your code what the variables are actually used for:

 

PersistentObject mainPersistentObject = PersistentStore.getPersistentObject(key1);  // Get ....

Object screenIndicatorValue =  mainPersistentObject.getContents()
System.out.println("persisted value is :  "+screenIndicatorValue);
if(screenIndicatorValue==null)

 

If you rework your code with names that make sense, you never know - you might find your problem. 

Please use plain text.
Developer
robert30
Posts: 191
Registered: ‎04-02-2013
My Device: BlackBerry Bold 9900
My Carrier: developer

Re: Problem in persistent value

Ok i will make it more meaningfull.

 

I have a mainScreen say Screen1 .

First time when i run my application screen2 will get open and then screen 3.

When i close my application and again open it then i directly move to screen 3.

 

For this i am taking persistent storage.Initially the value of persisntent object is null so i initially put flag as true in persistent memory.So, if the value is true i will move to screen2 otherwise screen3.

In screen 3 i have changed the vlaue of flag as false.

 

When i debug the application again, even then i am getting the flag value as false.

 

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem in persistent value

I am still confused, because you seem to be explaining this using a mixture of names, like Screen1 and Screen 2 and Screen 3 and overlay screen and sliding screen.  I don't know which is which, And you are saying things like the "the value of flag is true" and "the value is false", and you seem to have two flags here.  So I was hoping you would use something meaningful, like the 'overlayScreenShown' flag value is false.

 

I think you have a logic error, but I can't follow your code and your explanations because they don't seem to match up.  Maybe they do, but I don't have the time to analyze the code closely enough - I read it and get confused.  And I think you will when you read it in the future. 

 

 

Please use plain text.
Developer
robert30
Posts: 191
Registered: ‎04-02-2013
My Device: BlackBerry Bold 9900
My Carrier: developer

Re: Problem in persistent value

Sir

Forget about the code or the sliding screen or splash screen.

 

I have 3 screens Screen1, Screen2 and Screen3.

When my application starts for the first time , Screen1 gets open and then Screen2 then Screen3.

When i open the application for the second time, Screen1 gets open and then Screen3.

Means Screen2 will get open only 1 time when i run my application for the first time.

 

Please have a look at this link. Its more meaningful. I have tried this solution but its not working...

http://stackoverflow.com/questions/15743380/delete-persistent-store-data-when-app-is-uninstalled-del...

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem in persistent value

[ Edited ]

The approach given in the example should work for you.  If it does not, then most likely, there is a problem in your code.  Since very few of us are clairvoyant, we can't help with logic errors unless we see the code. 

Please use plain text.
Developer
robert30
Posts: 191
Registered: ‎04-02-2013
My Device: BlackBerry Bold 9900
My Carrier: developer

Re: Problem in persistent value

I have used the same code and its not working for me.

 

Please use plain text.
Developer
simon_hain
Posts: 15,870
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Problem in persistent value

does the sample app work for you?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
robert30
Posts: 191
Registered: ‎04-02-2013
My Device: BlackBerry Bold 9900
My Carrier: developer

Re: Problem in persistent value

No Simon Sir.

I have used the code and its not working. Still after i run the application again, i move to screen3 rather thar screen2.

Please use plain text.
Developer
simon_hain
Posts: 15,870
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Problem in persistent value

i don't mean "used the code", i mean "run the sample as it is provided".
if the sample works and your app does not look for the differences.
if the sample does not work (and i would be very surprised by that) we can investigate there.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.