Windows 8.1 Universal App Multitasking Foreground-Background Cycle - windows

Is there a way to know if the app is sent to background or brought to foreground. I don't mean Suspended and Resuming events.
For example, user leaves the app to check something on Facebook app for a min. And then return to back to my app. So suspention doesn't take effect on this scenario. Then how to know user is back to the app on app.cs level?

As stated in the MSDN documentation:
Your app doesn't receive an activation event when app visibility changes, because the app is still running. Windows simply switches to and from the app as necessary. If your app needs to do something when the user switches away and back, it can handle the visibilitychange event (for HTML) or Window.VisibilityChanged event (for XAML).

Related

Push FCM Xamarin like WhatsApp background

I have a problem on Devices Xiaomi and Lenovo Phones, when i close app from task manager they stop receive GCM messages, the gcm messages receive only at foreground and app on task manager list. How do i to keep app or service running on close at task manager? Obs: samsung phones keep as well on both cases.
As stated in this thread, Lenovo mobiles are using Background task killer to stop background apps. To hide task killer, untick restrict in application menu.
Also, as mentioned by #AL. in this post, it may very well be possible that when an app is stopped from multi-task tray in that device, it is actually killing the app, causing the services and other background processes associated with it to also be destroyed. Suggested action is to make use of the START_STICKY flag.
Another reference which might help.
In Xiaomi phones, they whitelist or blacklist an app based on certain criteria. If you download an app and if it is in their whitelist, they'll permit the app to show notifications. If not, you already know what happens. But the good thing is that you can change these settings. Look for an app named Security. If you revoke the right permissions, even WhatsApp will stop showing notifications.

Windows phone notification that stays till user checks

I am new to windows phone app dev. I want to know if there is any way to have a notification alive till the user checks it. I found that "toast notification" expires in 10 seconds irrespective of user checks it or not. And there is no way of finding out if a tile notification arrived or not. Is there any workaround? I want to have notifications that are similar to Android notifications which stay till user checks them.
Persistent on-screen notifications on Windows Phone are not possible, by intentional design. It's interesting to see how many users on Android disliked persistent notifications when applications started to interrupt and then disrupt the current foreground application experience.
The design philosophy is that they distract from the user experience and could be easily abused by applications.
The general Microsoft recommendation for the platform would be to use a combination of a notification, Live Tile (reference), and in application UI update.
In Android 4.3, the behavior was changed to highlight applications that were constantly running (interesting reference)
You can use "MessageBox.Show(String)".
Refer below for:
MSDN Doc
Example 1
Example 2

What is the difference between OnLaunched event and resuming event in metro application?

I am trying to understand the application life cycle.
Scenario: I am launching a blank application; after that I am intentionally coming out of that app and opening a separate app. After some time I look at the Task Manager. The blank app appears to be suspended. Then I launch the blank app again (which was in a suspended state). At that moment, it has to hit the resuming event, right?
1) Why is the resuming event not firing? (Resuming event should be fired because the app is coming from the suspended state into the running state.)
2) Why is the OnLaunched event fired?
3) Is the OnLaunched event fired only when the application starts for first time, or also when being activated after termination?
Thanks in advance.
I don't have much experience with Metro apps yet, but I'll try to answer:
Ad 1) If your application went from the Suspended to Running state (as in diagram in this MSDN article on Metro Application Lifecycle), resuming event should actually fire. I made a few tests in similar scenario and it did. And btw, here's the best description of this event I found:
When an app is resumed from the Suspended state, it enters the Running state and continues from where it was when it was suspended. No application data is lost, as it was stored in memory. Therefore, most apps don't need to do anything when they are resumed. However, the app could have been suspended for hours or even days. So if your app has content or network connections that may have gone stale, these should be refreshed when the app resumes.
Ad 3) Launch for what I understand is just a special kind of Activation (one of the possible entry points to application), which corresponds to transition from Not running->Running. Some quotes:
When an app is activated, for any reason, the system sends the
Activated event.
and
When the user switches to your terminated app, the system sends the
Activated event, with Kind set to Launch and PreviousExecutionState
set to Terminated or ClosedByUser. The app should load its saved
application data and refresh its displayed content.
Ad 2) If OnLaunched was executed and Resuming event wasn't fired, my guess is your app was in 'Not Running state', e.g. it was terminated by the system (Suspended->Not Running) before you re-launched it. I don't know why task manager might have not refreshed this information.
I can answer this one:
1) but why the resuming event is not firing ? (resuming event needs to fired because the app is coming from suspended state to running state )
There is a debug button available for you to force your app into suspended state. In the quick-search of visual studio search for "debug location". This is a debug toolbar that you tap on the "suspend" button when you are debugging. Once you go back into your app (give it acouple seconds before you go back in) then you should get the resuming event fired.
ResumeEvent is not firing because you opened the app from the start screen or from its pinned tile. In that scenario, the app is treated as having been launched again. That's why the OnLaunched event was executed and not ResumeEvent.
To make sure ResumeEvent is fired, wait for 10 seconds after switching to other app, and then go to the top-left corner and bring the app back to the foreground. Make sure to wait the 10 seconds, before then Windows treats the app as running.

How does Reminders launch the app?

I am having a few problems getting my Windows Phone 7 app-specific Reminders to work properly - the app re-closes after a fraction of a second after starting to show the splash-screen.
In order to debug this, I'd like to know how a Reminder launches an app, which events are fired and so on.
For what it might be worth - here is what I found out.
A Reminder restarts the app, triggering the Launching-event in App.xaml.cs. That is - you need to re-load anything you need to make the app work from Isolated Storage or the web
When the Launching event is done with, the app goes straight to the requested view - skipping any loading-page you might have made for your app. Again, remember to load whatever resources you need from Isolated Storage.
Then the app fires the view's constructor, before OnNavigatedTo and Loaded goes off.

How to run a WP7 silverlight application after some period of time?

I have an application in WP7 silverlight that needs to be launched after a specific period of time, something like an alarm.
But I want to launch the application itself not WP7's alarm.
I use:
this.Visibility = Visibility.Collapsed;
for hiding the application, I know it is not the correct way for making it run in the background.
Any hint please? Thanks.
The platform specifically does not support running apps in the way you describe.
If your functionality can't run in a background agent then your only options are to use an alarm or toast message (sent as a push notification) to prompt the user to start the app.
One of the design decisions behind the platform is that the user should always know what is going on on the phone so having apps stop and start by themselves would be contrary to this.
You can run a background agent and display a toast notification to the user , and launch the application when the user clicks on the toast.
You can also push toast messages to the device, and rely on the user clicking the toast .

Resources