I have this little problem.
I fetch data from network into a ListView using AsyncTask. If I press on an item it takes me to another activity. Then, if I press the 'back' button, the AsyncTask does not execute again. (Which is exactly what I want).
The problem is, if on the ListView I press the back button, and then I get into the listView activity again, the AsyncTask executes again.
I'm not sure if this is happening because the Listview's activity destroys and loses all reference, or if because onResume (I think) is recalling onCreate.
When you press back, you go back to the same old instance of the activity.
If you want the asynctask to run again you need to call its execute in onResume.
From what you have told, it seems you call the asynctask execute in the activity oncreate. When you go back from your listview activity and come back , you are creating the activity again and that is why your asynctask is executed.
onResume is always called after onCreate.
onResume is always called when your activity comes into focus.
Related
I have a problem with Xamarin.Forms.Buttons. I want my app to execute an action when the user presses the button, and a different action when the user releases it. The problem is that once you have pressed the button if you move the finger(while you are still touching the screen), the released event will never be triggered even when you release the finger. When you move the finger, the button makes the animation like it was released/lostFocused but the "Released" event is not triggered. If you press and release again the same button without moving the finger, both events are triggered.
I would like always to know when the user has finished pressing a button.
Is there a way to make the "Released" event trigger in that situation?
Can I make the button has a "IsPressed" property or something simillar, so I can check it?
Can I check for example a "Screen.IsPressed" to know that the whole screen is not touched anywhere?
Thank you very much in advance.
If I make a new project with a simple button, I am not finding that problem either. In the project that I have the problem, my button is part of a ViewCell that is part of a ListView. Maybe that is causing the problem. By the way, I was able to solve the problem using a CustomButton.
https://forums.xamarin.com/discussion/comment/423607#Comment_423607
I need to execute some native code to interact with the macOS menu bar, ideally immediately after it got initialised. IMHO, a good time would be right after the JavaFX application window becomes visible.
From the documentation, I thought that Window.onShown should do exactly that:
Called just after the Window is shown.
But that does not seem to be the case. When putting a breakpoint into the event handler for Window.onShown, the window is not yet visible. Unfortunately at this point, the macOS menu bar is not yet fully initialised, so all my changes to the menu bar would be overwritten later by JavaFX's default menu bar.
For now, I'm just using a delay of 1sec after the WindowEvent.WINDOW_SHOWN is sent, but that does not seem to be a good solution. So does anyone have a better idea on how to reliably determine when the window is actually visible or all initialisations have finished?
If you put a breakpoint in the onShown method the problem might just be that the window was created but you are blocking the visualization because of the debugger.
If this is not the case you could try to create a new Thread that only checks for the visibility of the window using the isShowing method of the class Window.
This should be faster than just waiting for one second after the onShown method was called.
I have a NSPopover that opens, and if the user clicks somewhere else in the app, the popover closes.
But the problem is that currently that mouseDown event is consumed during the popover-closing process.
Is it possible to still have that mouseDown event go through to the application, but also close the popover?
I had this same problem, so we changed to using NSPopoverBehaviorSemitransient for the behavior type. It no longer steals the mouseDown: and we just added some extra cases for closing the popover manually.
You can subclass the windows contentViewControllers view object.
I did this in the Storyboard file.
In there, implement the mouseDown() method. In there, you can create a notification which can be received at a point in your project where you need to know about the mouse event.
As the 'root view' captures almost all mouseDown() events, you have to filter them in order to only respond to the notification when the popover is displayed.
Don't forget to call super.mouseDown() at the end of your implementation.
I am attempting to handle the loss of focus of my application, either by a phone call or other event, and also by the pressing of the home key.
I have tried setting a flag in the OnNavigatingFrom/OnNavigatedFrom and OnNavigatedTo event handlers but each time the app starts (either after pressing home, or something else) it always seems to be resetting the flag.
Which are the correct events I should be using in order to correctly "pause" and subsequently "resume" my application if it loses focus?
You should read the documentation about application lifecycle.
When you press the Home button, or when you receive a phone call, the application is paused.
If you pressed Home, you can then restore the application by pressing the back button.
to handle these events, in App.xaml.cs by default the methods are: Application_Activated and Application_Deactivated
Of course you can manage to store data before the pause, and restore it when application is restored.
This is called tombstoning.
What you need is described in the following links:
http://windowsphone7.vectorform.com/2010/11/16/wp7-application-lifecycle/
http://www.windowsphonegeek.com/articles/WP7-Application-Lifecycle-and-Tombstoning
Read this. This is a microsoft tutorial on how to save state.
It'll give you how to save your ApplicationData when it is tombstoned.
Basically edit the Application_Closing and Application_Activated methods in the App.xaml to save the data to the system using isolated storage.
I am trying to handle state restoration on a sub-page of my app. I've hooked the OnNavigatedFrom and OnNavigatedTo overrides in order to do this. However - although they fire quite happily while I am navigating around the app itself, the OnNavigatedTo does not fire when I switch out of the app with that page active, then try to reactivate it. This is made all the more mysterious because another near-identical app I have seems to work fine.
Is there some sort of setting somewhere that might prevent OnNavigatedTo from firing when my app comes back from tombstoning, but allows it to fire when the user navigates around screens in my app?
Chris
If you're going back almost immediately, it may be possible that your app is still running the same as it was, but the OnNavigatedTo should still be fired even in that case (more recent info: link text).
Are you doing anything fancy in your constructors, such as hooking up event handlers to try and handle the state changes from the frame?
If so, drop that and see where it gets you, ctors should be mostly empty.