Android Webview - Prevent Reload When Go Back to the App - android-webview

How to prevent reload on webview when your back to the app? When tapping home key and then back to the app, the webview was reloaded. I dont want this behaviour, I want users to view the previous page (w/o reload) that they accessed.
private WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl( WEBSITE_URL );
}
thanks

Test this by adding android:launchMode="singleInstance" to your <activity> element in your androidmanifest.xml.

Related

Xamarin forms button stilling

I have Xamarin form application. In App.xaml.cs I have event handler for button. If I set different background color on click it works. If I have also navigation like Application.Current.MainPage.Navigation.PushAsync(new Page1()) color doesn't change. How navigation break background color change?
private void Navigate(object sender, EventArgs e)
{
Button? button = sender as Button;
if (button != null)
{
Application.Current.MainPage.Navigation.PushAsync((Page)Activator.CreateInstance(new Page1());
button.BackgroundColor = Color.FromHex("#332196F3");
}
}

How to make activity start at the bottom of the ScrollView?

I want to make a quiz application with levels. It has a long background image and as you scroll down, at the bottom I have the levels 1, 2, 3,...going up. How can I make the activity scroll at the bottom automatically when I enter the app?!
ScrollView scrollview = findViewById(R.id.scrollView);
scrollview.post(new Runnable() {
#Override
public void run() {
scrollview.fullScroll(ScrollView.FOCUS_DOWN);
}
});

Have webview selection and swipe at the same time

I have a webview containing some text. I need to be able to swipe on the webview and make text selection at the same time. The problem is after I have implemented the swipe overriding the onTouchEvent method, the other features of the webview seem to have freezed, links in the webview aren't clickable anymore, and the text selection (after longClick) doesn't work anymore, I need to make to implement the swipe and preserve the other features of the webview.
I tried to override the longClick click method as well and use the following method to implement text selection:
public void selectAndCopyText() {
try {
Method m = WebView.class.getMethod("emulateShiftHeld", null);
m.invoke(MyWebView.this, null);
}
catch (Exception e1) {
e1.printStackTrace();
KeyEvent shiftPressEvent = new KeyEvent(0,0,KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_SHIFT_LEFT,0,0);
shiftPressEvent.dispatch(this);
}
}
but it didn't work for when this method is called I only get the upper bar for copy/ paste/ search/ websearch... but no actual selection on the webview occur.

Monotouch Achievements and leaderboard viewcontrollers

Im having an odd issue with dismissing my achievements and leaderboard viewcontrollers.
The viewcontrollers display correctly and can be dismissed using the done button but only if you press it within about 15 secs of it being displayed, if you press done anytime after that my app just crashes. In the debugger i get a "unrecognized selector sent to instance" error.
I was guessing maybe the viewcontrollers are being garbage collected or something? I'd really appreciate any advice.
heres my code
public void checkAchievements(UIViewController view)
{
GKAchievementViewController gkview = new GKAchievementViewController();
view.PresentModalViewController(gkview,true);
gkview.Delegate = new gkviewdelegate();
}
public class gkviewdelegate : GKAchievementViewControllerDelegate
{
public override void DidFinish (GKAchievementViewController viewController)
{
viewController.DismissModalViewControllerAnimated(true);
Console.WriteLine("Dismiss Leaderboard");
}
}
Your gkview is getting garbage collected. Change it to an instance variable instead in your class to keep a reference to it.
So your code should look a little like;
GKAchievementViewController gkview;
public void checkAchievements(UIViewController view)
{
gkview = new GKAchievementViewController();
view.PresentModalViewController(gkview,true);
gkview.Delegate = new gkviewdelegate();
}

How to have an Activity that uses a ScrollView AND keep onTouch method working properly?

I have an Activity that populates two views on a ViewFlipper. I added an onTouch(View v, MotionEvent event) public boolean method to the Activity. The method is implemented so that when the person taps on the screen the ViewFlipper goes to the next view. It works great but some of the text is too long so I went into my XML file and surrounded the textfield in one of my ViewFlipper views with a linearlayout and then a ScrollView. But now when I'm viewing the fields that are too long and show a scroll bar, I can't display the previous view. The onTouch method in my main activity isn't being executed. I have not been able to figure this out. I've read some posts about implementing or overriding the methods in ScrollView but I don't know where to do this in my activity. Does anyone know how I can program ScrollView to not intercept but keep its ability to scroll the view?
ScrollView myScroll;
myScroll.setOnTouchListener(new OnTouchListener){
#Override
public boolean onTouch(View v, MotionEvent touchevent) {
switch (touchevent.getAction()) {
case MotionEvent.ACTION_DOWN: {
oldTouchValue = touchevent.getX();
break;
}
case MotionEvent.ACTION_UP: {
float currentX = touchevent.getX();
if (oldTouchValue < currentX) {
//left swipe
return true;
}
if (oldTouchValue > currentX) {
//right swipe
return true;
}
return false;
}
}