I asked a question recently about how to disable the back button is Android, after a while I got it working with these lines of code
public override void OnBackPressed ()
{
// base.OnBackPressed (); /* Comment this base call to avoid calling Finish() */
// Do nothing
}
And just recently someone commented this
Disabling the back button is counter-intuitive and breaks the device
usage contract imposed by Android. So i suggest you rethink.
-Question-
What would be a possible change to this? I dont want to be able to press the back button when playing my quiz game because that would make be able to cheat. New to android Development
Instead of simply making the back button do nothing, you could have it create a popup asking something along the lines of "Are you sure you want to leave the quiz? (This will count as a loss)". And have it take the user back to the main page of your app if he confirms (instead of back to the previous page).
Why not imitate what many websites do and make it so going 'back' to a page works but doesn't display any information?
It depends on your code, but perhaps you can make your buttons and text (or whatever it is you don't want them interacting with) change to be unseen whenever they move on to a new page. Or just throw up a message that says 'You can't do that' to cover the page that they'll only ever see if they go back to view it again.
Related
I want to use template 10 to develop my app, but I dont know how can I hide the back button once I pass from one page to another, like for example passing from a login page to my main page.
With template 10 it always show the back button, I know how to prevent from going back, but still I can see the damn back button on the shell, I dont wish to see it.
How could I hide it?
ClearHistory is located on the HamburgerButtonInfo as a DP and if that isn't enough you can thru the NavigationService call ClearHistory as well which looks like public void ClearHistory() => FrameFacade.BackStack.Clear(); in the source so you know what it actually calls...
We have a Xamarin app (Android) that at one stage opens up a web view (Webkit.Webview not Forms.Webview). This directs the user to a page on a third party site which has been set up for us.
Firstly - on certain input fields the keyboard which shows up is the wrong one - we are expecting a dismissable keyboard (i.e. "Done" in the bottom corner, not a "Submit"). I know this can be changed but not sure what is the correct way to do this. Does it have to be the metadata/text inputs on the web page that is changed? If so - what needs to be modified per text box entry on the html of the page? Just the type? i.e:
<input type="email">
Secondly, rather than wait for the third party to fix the page, is there a way we can force the webview to always open a certain keyboard type?
We have an option of intercepting the keyboard key presses and trying to dismiss the keyboard on return press at the minute. But would prefer not to put a hack in that intercepts every key press.
Appreciate the help, not sure what the way forward is here.
Thanks
From the comments: To your second question about forcing a keyboard button, you can check out this link which describes how to override OnCreateInputConnection to specify the Keyboard Enter Button type.
public class MyWebView : WebView {
...
public override IInputConnection OnCreateInputConnection (EditorInfo outAttrs) {
var inputConnection = base.OnCreateInputConnection (outAttrs);
// outAttrs.ImeOptions in Xamarin only allows ImeFlags but it also should allow ImeActions
outAttrs.ImeOptions = outAttrs.ImeOptions | (ImeFlags)ImeAction.Next;
return inputConnection;
}
}
That will not dismiss your keyboard when tapped though since it is meant to take the user to the next input. Hopefully someone else can come along and either provide a better answer or give a good way to dismiss the keyboard in this situation without hacking something together.
I made a simple Windows 8 quiz game.
I have 3 pages: MainPage, GamePage and ScorePage
The GamePage has a timer so I have to answer as many questions in 30 seconds as I can. It also has a Back button in case I want to give up and a Retry button to start over.
The problem is that whenever I click the Back or Retry button, the new page is displayed correctly but the old GamePage still works in the background and when the time is up it will display the ScorePage
For example I open the app, start the game and click Back. After the time is up, even if I closed the game (or so i thought), the ScorePage will still be displayed...
So how can I completely dispose of that instance of the page?
It is the first time I tried to make a W8 App, I only used WinForms before, where I used this.Close(); to completely get rid of the pages/forms.
To open pages I used this.Frame.Navigate(typeof(GamePage), null); and this.Frame.Navigate(typeof(ScorePage), new int[] { Correct, Wrong });
The below code remove back entries from the stack
if (NavigationService.CanGoBack)
{
while (NavigationService.RemoveBackEntry() != null)
{
NavigationService.RemoveBackEntry();
}
}
You can close the app this way
Application.Current.Terminate();
I am currently trying to implement a navigation scheme that closely resembles that of the Internet Explorer app on Windows Phone 8.
The IE app can have multiple tabs that the user can switch between. Each of these tabs has its own history. Hitting the Back Button on the phone takes you to the previous page in that tab's Navigation history (Not the PhoneApplicationFrame.BackStack). If there are no previous pages, the back button takes you to the previous opened tab or, if none, exits the app.
Why this is troubling me
Application.RootVisual can only be set once. So you can't have two PhoneApplicationFrames, each with its own BackStack, to swap RootVisual between the two.
You cannot traverse the BackStack (it is a Stack, after all). Can only call GoBack(). Calling GoForward() will throw an Exception.
PhoneApplicationFrame.GoBack() removes entries from the BackStack which can only be added again through the PhoneApplicationFrame.Navigate(...) method. So, manipulating the BackStack is a no-go.
Bright Ideas
Keep a Dictionary<enum, List<string>> which is updated with each call to a custom NavigationService.Navigate(tabTypeEnum, uriString, params). This will keep the Navigation history for each tabType, allowing us to possibly Navigate through the current Tab's history when the BackKeyPress event is handled. Bad thing is, calling Navigate(...) to go to previous pages (instead of GoBack) will add to the BackStack. So requires maintenance that hurts my brain right now.
Create a custom NavigationAwareTabPage : PhoneApplicationPage, which keeps track of its own navigation history and fakes navigation by animating a transition when its Content is changed. The only time we call a true Navigate is when we switch from one tab to another. (I think this is what the IE app does.) And the BackKeyPress would have to look like below.
This:
void RootFrame_BackKeyPress(object sender, CancelEventArgs e)
{
var rootFrame = sender as PhoneApplicationFrame;
if (rootFrame.CanGoBack)
{
// Get the NavigationAwarePage
var navAwarePage = rootFrame.Content as NavigationAwareTabPage;
if(navAwarePage.CanGoBack())
{
// This method "navigates" to the next page
// by changing the navAwarePage.Content
navAwarePage.GoBackToPreviousPage();
e.Cancel = true;
}
}
}
Has anyone been down this road?
All the magic of how ReactiveUI overrides the Back button is here:
https://github.com/reactiveui/ReactiveUI/blob/master/ReactiveUI.Mobile/WP8AutoSuspendApplication.cs#L91
The way that this works in ReactiveUI is that there is a content control named RoutedViewHost that is listening to the Back being signaled (you can do whatever you want in response to the hardware Back button and cancel the default action). ReactiveUI maintains its own ViewModel-based back stack and manipulates that instead of using WP8s, and you never call WP8s navigation methods.
This effectively means that, from WP8's perspective, there is only ever one page in the entire application. WP8 really wants to create that page itself, and it's specified in WMAppManifest.xml.
Don't try to participate in WP8's Frame system, it really wants to work its own way and you won't be able to convince it otherwise.
One last important thing, if you're at the bottom of your back stack, you must allow the default Back action to happen (i.e. what WP8 wanted to do, take you out of the app). Otherwise you'll probably fail Certification and you're Doing It Wrong™.
I'm tired and hungry, so I might of missed it, but from what I can see no existing post covers this...
I'm writing a plugin for an application. My plugin loads a form to get some data specifically, it uses the webcam to scan for a barcode. Once it's found a barcode, the form hides itself (incase it's needed again later). This is how I currently call the form that does the barcode work:
string readData = null;
if (eye == null)
{
System.Windows.Forms.Application.EnableVisualStyles();
eye = new CamView();
}
eye.Show();
if (eye.found)
{
readData = eye.readData;
}
return readData;
So, my problem is that eye.show() doesn't block. It makes the form appear and carries right on before there's a chance for the barcode to appear. I imagine I need to use some form of threading or locking, but my crude attempts to do so have just frozen the interface completely.
The "eye" form is basically just a viewfinder for the webcam, and relies on the camera_OnImageCapture event to make it do it's image checks for the barcode.
Is there an elegant way to make the application calling the plugin wait for the form to finish? Or do I just need to add an accept button to the "eye form?"
Cheers. And humble apologies if this is in anyway a repost.
.ShowDialog();
http://msdn.microsoft.com/en-us/library/c7ykbedk.aspx
"You can use this method to display a modal dialog box in your application. When this method is called, the code following it is not executed until after the dialog box is closed."
You are on the right track. You change the code to show CamView as a modal dialog but do no add an Accept button. Instead change camera_OnImageCapture to close the dialog.