How to suspend metro app on button click? - microsoft-metro

I just learnt that terminating the app in the code is not recommended, but how do I suspend an app in the click event of a button? I have a Close button in my app when clicked, should suspend the app. I don't want the user to hit ALT+f4 or anything. When the user clicks the app icon again from the Start icon, it should resume the app. How do I do it?
I'm looking for something like -
private void btnSuspend_Click(object sender, RoutedEventArgs e)
{
//Suspend App.
}

An app cannot suspend itself. Windows manages the lifetime of Windows Store apps automatically. An app will be suspended after a timeout of approximately ten seconds when it is no longer visible, or when the machine goes into a low power state. When the user reactivates the app again (through Start, Alt-Tab, etc.) Windows will resume the app.

Related

How to automate native features (like take image in camera) or pop-ups (tapping on allow or deny) in flutter integration testing

Every time I log in to my flutter app using integration test script "Allow user to access contact" pop up will be displayed which is a native component. I could not access or tap those pop ups using flutter test driver. Is there a way to automate those process or any work around for it?
Native pop ups cant be handled in integration test except to simulate a tap at a specific position.. or may be give a timer for you to manually click on that pop up..
await tester.pump(Duration(seconds: 15));

How to make my flutter app return the user to the OS home screen?

I'm working on an app that will have a lock screen, but I'm having some issues getting it to behave correctly. Right now I'm using the didChangeAppLifecycleState to navigate to the lock screen when the user suspends/resumes the app. I'm also using the WillPopScope to intercept and deny the back button. The problem with this approach is that pressing the back button and having nothing happen doesn't feel super intuitive. Ideally, I'd like the back button to take the user out of the app and back to their OS home screen when they're on the lock screen. I also want to do this in a way that the user's route history is maintained for when they successfully unlock the app.
Is there any way to accomplish what I'm trying to do, or should I just accept that the back button won't do anything on the lock screen?
You can create an identifier in your LockScreen state and check for the identifier in onWillPop and if the user is pressing the back button from the lock screen, exit the app.
String identifier = "lockscreen";
bool onWillPop() {
if (identifier == "lockscreen") {
SystemNavigator.pop();
SystemChannels.platform.invokeMethod('SystemNavigator.pop'); //preferred.*
return true;
}
}
SystemNavigator.pop(): On iOS, calls to this method are ignored because Apple's human interface guidelines state that applications should not exit themselves.

how to load aplication from start up page each time in iphone

I have application for iphone i want to open it from start up page always but when i load first time app on ipad it loads from startup page but when i close app and second time run on ipad then it opens from the same screen from where i left i want that again it should open from startup page also.I have start up page with enter button when i click to button i move to calulations screen where i perform calculations .If i close on calculation screen the app when i again open it it opens from calculation screens not from the startup screen
In plist file add one more field
Application does not run in background : make it true
This is your perfect ans.
Second time app will be in Background thats why it is not starting with start app page. Dont allow application to run in background. Set Key "" in info.plist file
You should add in your plist that property :
UIApplicationExitsOnSuspend
This will allow your application to "restart" instead of saving its state. This will allow you to load the start up page each time.
(documentation)
Well it is discouraged by apple , according to it's documentation:-
There is no API provided for gracefully terminating an iOS application.
In iOS,user presses the Home button to close applications. Should your application have conditions in which it cannot provide its intended function, the recommended approach is to display an alert for the user that indicates the nature of the problem and possible actions the user could take — turning on WiFi, enabling Location Services, etc. Allow the user to terminate the application at their own discretion.
Warning Do not call the exit function. Applications calling exit will appear to the user to have crashed, rather than performing a graceful termination and animating back to the Home screen.
Here's the link to it.Anyway nobody stops you from using
exit(0) , but is discouraged.
Another way to do is is simply change your application's pList property "Application does not run in background" to true.

How to maintain state of android activity

I am new to android.I created an activity in which i add text view dynamically on button click event.After adding text view i click home button of my phone.When i start the application after 1 or 2 hour the added text view is disappeared.Kindly help me out to solve this issue.
Thanks in advance.
That probably means that your application has been terminated at some point by Android.
Even if you press the Home button leaving the app running in background, it can be killed by the system if it needs to free resources.
Here's how to use SharedPreferences to save the application status and restore it once the app is restarted: http://developer.android.com/guide/topics/data/data-storage.html#pref

On Android or iOS - how to approach the possibility of a service or app going into a broken state

...and this broken state persisting until a device restart, since a naive attempt to restart an app would not work. Many users are not savvy enough to know how to terminate services/backgrounded apps. If the user can't (or doesn't 'need to') close apps, then what about restarting apps which have gone wrong? ( It can happen :) ) If my app goes wrong on someone's phone and they cannot easily restart the app without restarting the phone, that seems like a problem. I am aware that apps and services can be terminated by navigating system menus or double tapping the home button etc. but - many users are not aware of these features. For this reason I am thinking of adding an explicit close button to my app which will kill everything to the best of my ability, such that on a subsequent launch the program runs from the beginning again. I realise this is not the 'recommended' approach. Thoughts?
Thoughts?
Don't do it. Instead you should put a FAQ entry on your apps website that says.
Q: My app does not run anymore. HELP!
A: First you should try to restart the app. If that doesn't work feel
free to contact me.
Here is how you do this on the iPhone,
iPad or iPod.
double press the home button. the
multi tasking bar appears.
[ some screen shots ]
long press the app icon and press the
little x that appears on the icon.
[ more screenshots ]
If you want to put buttons for functions that are not obvious for many users you end up with a button for everything. And I (as somebody who knows every function) don't want a button cluttered user interface.
You would be surprised how many emails I get about "how can I zoom?" (A: Pinch your fingers) or "how do I delete an entry (in a tableview)" (A: Swipe your finger over the entry from left to right, and press the red delete button).
If I get an email about this I just point them to the faq which has some nice screenshots.
Btw, if the "broken state" happens so often that you would consider adding a special button I would check my code for bugs again.