2017년 5월 25일 목요일

How to set notifier to appear just once


I'm trying to build an app that allows the user to enter many values. In certain values, I want leave him/her a message through the notifier however, it is supposed to appear just once (moment after the user enter the info and right now it is appearing every time the screen initializes). Is there any way to do this? 

--
What you might do depends on what you told you app to do.  Since we do not know what conversation you had with your blocks you have to figure out when you want it to behave one way and when you want it to do something differently.  You might have seen this advice about how to let your app make a decision, 
Chapter 18. Programming Your App to Make Decisions
Since it is happening 'every time the screen initializes) you might have to use a Boolean value or something else to transfer how you want the notifier to show or not show (Notifier.Visible can be set to true or false). if for some reason you decided you could not use 'virtual' screens instead of switching between screens.  Switching between screen frequently a lot of necessary complex coding to make it work.possibly part of your issue.

Why not do a little reading about how you can tell your app what to do for itself and then try some blocks.   If you still cannot make this work, perhaps it would be a good idea to share you relevant blocks with the forum?

-- 
I think the notifier component can't be set to invisible... I used a clock to try stopping the notifier after the message is once showed, but it didn't work.
I send you here a print of my code. The block is inserted in the control lock 'When screen initialize".




-- 
You are right, Notifier cannot be set to visible=true or false...my mistake.

When you reopen your Screenxxxx the initialize block fires, so the app polls the last know glucose value you stored in the TinyDB.
You actually tell your app to show the Notifier every time you open this particular screen.

Setting the GlucoseLevel1  tag's value to 0 at when you close this screen might fix the issue when you reopen it, .  If GlucoseLevel1 is >= 110  the Notififer2 will fire.A value of 110 ensures you will see the 
notifier every time you open the screen unless the value is less than 110.

-- 
But my intention is to store the values so I can't change them to 0, I'm not really sure if I understand what you are saying

-- 
OK then you are going to have to move the block calling Notifier2  or rewrite your code because the REASON the notifier keeps showing is because at present the if statement tells it to display the notifier.  You have to change your if statement.  To what I do not know because I do not know what else you are doing.

What I say is that if the TinyDB has a value of 110 or more, your block says that you want to show the notifier.   I suggest 0 because that won't trigger the If statement condition.

-- 
You could define a global variable notifiershown (or similar) initialized to false. Then,place the notifier in an if block: if not notifiershown, then show the notifier and set the global variable notifiershown to true.
You must reset the global when for some reason you want the notifier to be shown again.

-- 
And how exactly I can associate the global variable with the notifier? 

-- 


Like this. After the notifier is shown once, the global variable notifierShown is true and you will skip the then part of the condition.
If you later decide that the notifier should be shown again (once), then set the global to false.

-- 
It's still not working :( The notifier shows every time I enter the screen

-- 
The Notifier shows up because your code tells it to open  every time you open this particular screen.  If you followed Ghica's advice, you might be part way to a 
solution.  I suspect the issue is more than the Notifier there are other hints in your code that you are possibly misusing the TinyDB too.

 You did not post an image of how you modified your blocks. So, who is to know?

-- 
My code right now is the same but with Ghica's hint. The only difference is that Ghica used a label and I'm using a TinyDB block in the if statement but I don't think that's the problem. Possibly is related to the fact that I put this code in the block "When screen incialize" but I'm not seeing another way. 
The idea is make the notifier appear when the value is 110 or more, but just one time because after that the user will eventually put more values and they may not correspond with that warning that is showing up.





-- 
Maybe you should pay more attention to what Steve says and maybe show more of your blocks (because we do not see the relevant ones) and/or post an .aia

You should go through Screen1.Initialize only once.
If that does not happen, this is because you are closing another screen and then opening Screen1 again.
Look here to find out how to do this right: http://puravidaapps.com/manager.php

manager.aia

-- 
I didn't show the rest because the code is really huge and basically the same over and over again and I was thinking that code was enough. Anyway, here I send the app in aia. The screen that I was talking about is called "Register_Glucose" and the values that appear in this labels come from the screen "AddNewBGResult".


I really appreciate your help, thanks for your tips. If you find out what's going on let me know. I'll read what you guys recommend!


-- 
I opened your project, but there is no way I am going to find out what is wrong.
Please take some time to learn more about app inventor, especially about procedures in this case.
If you can avoid repetition by using procedures, your app will become a lot clearer. As a rule, a block that is longer than my screen, smells like something could be simplified.

-- 
Ok thanks anyway!

-- 
I looked at your blocks.

You set it up so that you need to add components and blocks for each new
piece of data.  Your current hard wired limit for readings is 10 readings,
so at 20 readings you would have doubled the size of your app.

If this is just for personal use, consider switching to Fusion Tables.

Do the tutorials for lists and TinyDB in this FAQ for examples
of how to deal with an unlimited amount of data:

-- 
I should have added that I admire all the energy you have put into this. I just wish that you would have asked for help much earlier.
Maybe you can appreciate Abrahams advice much better now though.

-
This can be made to work without the code Ghica provided. Your original code could work properly.   When you use the Register_Glucose screen  Initialize, you check all the Log number  items .  For example, if any 
of the 10 log number arrangements show a value that triggered  a display of the Notifier2   , perhaps  saved as a @ 2 log slot then you have a problem when you log an OK value in log number1.   Why?  because when the info is updated,  the notifier for log number2 will display when you log the new OK BG value into log number 1.   The more log numbers that are 'filled' and the problem gets worse.

If you only used a single screen, this would be an easy fix. You only really want to update the log number you are working on.  This is available on the data entry screen from the ListPIcker.   Because you use multiple screens it is difficult to tell the Register_Glucose screen you are only updating the log number 1.

This is why you have issues with the Notifier popping up.   You can either eliminate the Notifier2 ... since you color code the BG value  or you can figure out how to only update screen Register_Glucose with the Log number you select on the data info screen.


-- 
I already solve the problem, thank you all!

-- 

댓글 없음:

댓글 쓰기