what is the Function that takes place upon reopening app - xamarin.forms

I created an app using Xamarin.Forms. I am trying to detect if there is a change in phone's language each time the app is reopened after being closed using the back button. Tried to Debug.WriteLine on each of onStart, onSleep and onResume to see which one occurs when I open the app again but none of them worked. This is what i tried:
App.xaml.cs
protected override void OnStart()
{
Debug.WriteLine("onresume");
//CultureInfo language = CultureInfo.InstalledUICulture;
//Thread.CurrentThread.CurrentUICulture = language;
//ApplicationResource.Culture = language;
//Application.Current.MainPage = new NavigationPage(new MainPage());
}
protected override void OnSleep()
{
Debug.WriteLine("onsleep");
}
protected override void OnResume()
{
Debug.WriteLine("onresume");
}
How do I know when the app is reopened so I could try the language change code?

If i understand your concern correctly two things can help you:
On android you can have a very wierd behavour if you do not specify SingleTask for your mainactivty. Basically if you "close" the app using Back button and then click on app icon, the app is launched from start recreating App but keeps static variables and the debugger is still connected too. You can detect it setting a static variable, then checking it with a breakpoint inside App.cs constructor. So the avoid such just use LaunchMode = LaunchMode.SingleTask inside the MainActivity.cs [Activity] attribute. This way after you return to the app after the Back button + click on icon you'll get a fresh new app with OnStart invoked.
Some could say to use LaunchMode.SingleInstance but it will kill your app if you click on push notification whie app is active so better use SingleTask, it will open smoothly the running app.
To store and retrieve data between app launches use local persistent storage, full docs: https://learn.microsoft.com/en-us/xamarin/essentials/preferences?tabs=android. So when you got your language store it, then at app start (App.cs constructor) check values.

I had done a simple to test your code with the Android simulator. And I use the Console.WriteLine instead of the Debug.WriteLine.
I had found that:
When the app exited with the back button, it will call the OnSleep method and if you get into the app in the recent task, it will call the OnStart method.
When the app go to background with the home button, it will call the OnSleep methed too, but if you get into the app in the recent task, it will call the OnResume method.
So if you add a break point in the OnStart method, when you exit with the back button and get into the app again, it will hit the break point.

Related

React native, Firebase notification quit state listener re-fire after refreshing app

I'm using React native 0.65.1 and "#react-native-firebase/messaging": "12.8.0", and have messaging().getInitialNotification() listener for cases that the app opened from quit state by notification.
Besides that, I have multiple languages in the app, and in case a user changes his language from RTL to LTR (or the other way around...), I'm calling
import RNRestart from 'react-native-restart'
RNRestart.Restart()
The problem is, that in case the user started the current session of the app (only from a quit state) by a notification, if he will change the language in the same session in a way that causes refresh, the getInitialNotification listener will be fired again (with navigation or UI manipulation that's not needed).
Searched through the docs if there's any way to delete a message after the first time of listener runs, couldn't find any, and don't have any other idea how to encounter this issue (open as well for a suggestion on how to fix it from the other end of Restart, if someone has an idea how to switch from RTL to LTR in another way or with equivalent method/library that won't cause this issue).
(onNotificationOpenedApp (from background state) and onMessage (on foreground state) don't create this issue...)
Thanks in advance :)

Don't know how to kill app process in KaiOS

I am developing an app that uses ws connection on KaiOS. When I press back and put the app in the background, somehow the app instance is not killed. I can still get message coming in from ws connection even though the app is in background. This makes the phone runs out of battery quickly because exited app remains in the runtime process I suppose.
But, I do need a situation where the app runs in background (not killed).
So, the question is, do we have access to kill an app process, for example when user press something or normally when app is closed and screen back to menu screen from app screen?
I think you can observe the Backspace key and close the window.
Such as:
function handleKeydownEvent(e) {
if (e.key == 'Backspace') {
e.preventDefault();
window.close();
}
}
document.body.addEventListener("keydown", handleKeydownEvent);

Is it possible to implement asynchronous Outlook addin FormRegionShowing event handler?

I tested a simple asynchronous FormRegionShowing event handler
private async void MyForm_FormRegionShowing(object sender, System.EventArgs e)
{
await Task.Delay(3000);
}
When I debug this code in VS and await command works OK. FormRegionShowing event fires only once and only one MyForm instance is shown in email preview pane. However, when add-in is installed on test machine by add-in's setup program, FormRegionShowing event fires twice. As a result, two MyForm's are shown in preview pane. I attached Visual Studio 2015 debugger to OUTLOOK process and this is what I figured out. When event fires first time, the program leaves MyForm_FormRegionShowing method after it hits await Task.Delay(3000) command. Immediately after that, FormRegionShowing event fires second time. In this time, await Task.Delay(3000) command completes. But, because event was fired twice two MyForm instances are shown in email preview pane. Do you know why this happens? Thank you.
Looks like the add-in or the pane was registered twice on the end user machine. I'd recommend creating a new sample add-in from scratch to make sure the issue doesn't depend on the pane or add-in.

watchOS1 - When notification arrives, first InterfaceController loads too

Every time the Watch receives a notification (let's say local), either the static long look or the dynamic long look interface is loaded.
However, what I am observing is that every time the corresponding watch app's first interface controller is also getting loaded.
Is it something that other people have also observed?
Every time the Watch receives a notification, the watch app's first interface controller also gets run behind the scenes.
If it really does, how to distinguish when the watch app ran because user opened it and when it ran because there was a notification that came? context in awakeWithContext: is null in both cases.
Yes, I noticed too. It also seems it is in charge to handle the action methods for for local and remote Notification when tap on a button:
handleActionWithIdentifier:forLocalNotification:
I think you can use:
didReceiveRemoteNotification:withCompletion:
or
didReceiveLocalNotification::withCompletion:
to detect when your app is populated from a remote or local notification
As of watchOS 3 you can out exit of awake(withContext:) early in this scenario by inspecting the applicationState of your extension:
override func awake(withContext context: Any?) {
if #available(watchOS 3.0, *) {
if WKExtension.shared().applicationState == .background {
print("Awake with Context in background. Not processing.")
return
}
}
// otherwise, load normally
}

Removing push notification crashing app

I have created an app in Sencha Touch 2 with GCM plugin. Everything working fine with push notification but when clearing notification, its killing app.
I have no idea of java, but still tried to fork GCM java code but didn't got any success by the solutions found after googling around,
Few solution(google gave ;) ) tried but no success:
- ExceptionHandling
- onResume() function
After researching lot, found onResume isn't getting even called and app is killed much before. I dont know how to debug it. Using cordova to build & webstorm IDE.
Some saying less memory space might kill app but after testing on many devices found memeory isn't the issue.
Plz help me out as already wasted much time on it.
Not sure exactly what is wrong here, but as per you mentioned I am guessing the problem is with the handling of the event when the notification is clicked in order to open the subsequent activity. Please have a look at this code.
#Override
protected void onHandleIntent(Intent intent) {
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, LoginActivity.class), 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("New Message!");
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
}
Please make sure you implement the onHandleIntent() method after the notification is tapped so that it opens the activity where it should actually be.

Resources