Android studio Same activity back press - android-activity

Android Studio Same page visible for same activity onbackpressed
public void onBackPressed() {
// do something on back.
startActivity(new Intent(MainActivity.this, MainActivity.class));
return;
}
}

Related

How to capture chrome browser close event in GWT?

Trying to capture browser close event in Chrome. tried below code for Chrome and event doesn't get fired when closing browser but works in Internet explorer.
Window.addCloseHandler(new CloseHandler() {
#Override
public void onClose(CloseEvent event) {
SC.say("on window close event");
}
});
Window.addWindowClosingHandler(new ClosingHandler() {
#Override
public void onWindowClosing(ClosingEvent event) {
SC.say("on window closing event");
}
});
how to capture the browser close event for Chrome in GWT?

FreshMvvm - PopPageModel not works on Android

I have a Xamarin.Forms app and I am using FreshMvvm framework.
If I do this from ViewIsAppearing method of FirstPageModel:
CoreMethods.PushPageModel<SecondPageModel>();
I go the "SecondPageModel". Then, when I am in the "SecondPageModel" if I do:
CoreMethods.PopPageModel();
or press hard back button, or press title bar back button not works in Android (anything happens). I am using FreshMasterDetailNavigationContainer.
In iOS it works OK, I get back to FirstPageModel.
This is because ViewIsAppearing will always be called when the page starts displaying on the screen. When you pop the second page then go to the first page, the first page's ViewIsAppearing will fire again. It caused a dead cycle and prohibited your app from returning to the first page.
Add a property to avoid that:
bool isInitialized;
public FirstPageModel()
{
// ...
isInitialized = true;
}
protected async override void ViewIsAppearing(object sender, EventArgs e)
{
base.ViewIsAppearing(sender, e);
if (isInitialized)
{
await Task.Delay(100);
await CoreMethods.PushPageModel<SecondPageModel>();
isInitialized = false;
}
}
iOS may optimize this process, but I still recommend you to add this judgment statement.
Update:
Call it when your app has reached the main thread.
protected override void ViewIsAppearing(object sender, EventArgs e)
{
base.ViewIsAppearing(sender, e);
if (isInitialized)
{
Device.BeginInvokeOnMainThread(() =>
{
CoreMethods.PushPageModel<SecondPageModel>();
isInitialized = false;
});
}
}

Back Button in webView

When the user clicks on back button, I've implemented the following code that works very well for links inside of my webview:
#Override
public void onBackPressed() {
if (this.webViewFragment != null && this.webViewFragment.canGoBack()) {
this.webViewFragment.goBack();
} else {
super.onBackPressed();
}
}
My problem is that I have native menu in Android, and when the user clicks on the menu Profile for example and then clicks on the menu Dashboard, the back button doesn't work. Nothing happens. As I said before, just works for links clicked inside of the webview.
Anyone knows a solution for that?
or try this
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && web.canGoBack()) {
web.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}

Facebook SDK crashes after Login

My code seems to crash on Android with NullPointer exception. But works on ios simulator.
private void CallFBInit()
{
if(!FB.IsLoggedIn){
FB.Init(OnInitComplete, OnHideUnity);
}else{
shareDialog();
}
}
private void OnInitComplete()
{
FB.Login("email,publish_actions",fbLoginCallBack);
}
private void fbLoginCallBack(FBResult result){
shareDialog();
}
#region FB.Feed() example
public bool IncludeFeedProperties = false;
private Dictionary<string, string[]> FeedProperties = new Dictionary<string, string[]>();
private void CallFBFeed(FBResult result)
{
shareDialog();
}
private void shareDialog(){
Dictionary<string, string[]> feedProperties = null;
if (IncludeFeedProperties)
{
feedProperties = FeedProperties;
}
FB.Feed(
toId: FB.UserId,
link: ConfigCS.FeedLink,
linkName: ConfigCS.FeedLinkName,
linkCaption: ConfigCS.FeedLinkCaption,
linkDescription: ConfigCS.FeedLinkDescription,
picture:ConfigCS.FeedPicture,
mediaSource: ConfigCS.FeedMediaSource,
actionName: ConfigCS.FeedActionName,
actionLink: ConfigCS.FeedActionLink,
reference: ConfigCS.FeedReference,
properties: feedProperties,
callback: CallbackForFeed
);
}
#endregion
void CallbackForFeed(FBResult result)
{
if(result.Error!=null){
errorMessage=ConfigCS.fbError+result.Text;
showError=true;
return;
}else{
Debug.Log ("FB Feed error");
}
return;
}
private void OnHideUnity(bool isGameShown)
{
Debug.Log("Is game showing? " + isGameShown);
}
#endregion
I coul'dnt figure out why. When the login dialog is shown, and returns to the app, the app crashes. But if i try again, (since the user is considered logged in), it works without a hiccup. Can somebody see any error in my code?
edit:
To be more precise
1. when user clicks share, fb login dialog opens
2. Once the user successfully logs in, and returns the app, the app crashes with nullpointer exception
I open the app again, and click share (at this point the user is already logged in before the crash) and it works.
I coul'dnt pin point the error since adb log just says NullPointException in facebook.loginActivity.
My initiating function is CallFBInit();
Edit:
One more thing i have noticed is, i have installed facebook sdk 4.3.3 but it shows 4.2.5 in the console
and in the editor
This seems to be a problem with the new 4.3.3 SDK
I have downgraded to 4.2.4 and it works fine.
Is this a known problem?

GWT button click event

i have one window panel in my project.
and i add one button to it.
when i click the button,i want two event to fire.
one event is to hide that window,which i achieve through
Button button = new Button("click");
button.addListener(new ButtonListenerAdapter(){
#Override
public void onClick(Button button, EventObject e) {
hide();
super.onClick(button, e);
}
});
Window.add(button);
and second i want to pop up another window at the same time on the same button click..what to do?
help me out
I think this should solve your problem :
final boolean evenClick = false;
Button button = new Button("click");
button.addListener(new ButtonListenerAdapter(){
#Override
public void onClick(Button button, EventObject e) {
if (!evenClick) {
hide();
super.onClick(button, e);
}
else {
//DO YOUR SECOND CLICK STUFF
}
evenClick = !evenClick;
}
});
Window.add(button);