[android-developers] Re: Confirmation with pressing back button

2012-05-12 Thread Matt Clark

>
> Probably not the most efficient way to do things... but it works on all 
>> devices that I have used... Not neat.. but hey, it works. xD
>
>
> boolean quitOnBack = false; public void onBackPressed() { if (quitOnBack) 
> { finish(); } else { quitOnBack = true; Toast.makeText(this, "Press {Back} 
> again to quit.", Toast.LENGTH_SHORT).show(); new Thread() { @Override 
> public void run() { try { Thread.sleep(2500); } catch (Exception e) { } 
> quitOnBack = false; } }.start(); } }
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Confirmation with pressing back button

2012-05-12 Thread Matt Clark

>
> Probably not the most efficient way to do things... but it works on all 
> devices that I have used... Not neat.. but hey, it works. xD


boolean quitOnBack = false;

public void onBackPressed() {
if (menuLayout.getVisibility() == View.VISIBLE) {
menuLayout.startAnimation(Anim_SlideOut_Bottom);
menuLayout.setVisibility(View.GONE);
} else {
if (quitOnBack) {
finish();
} else {
quitOnBack = true;
Toast.makeText(this, "Press {Back} again to quit.", 
Toast.LENGTH_SHORT).show();
new Thread() {
@Override
public void run() {
try {
Thread.sleep(2500);
} catch (Exception e) {
}
quitOnBack = false;
}
}.start();
}
}
} 

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Confirmation with pressing back button

2012-05-10 Thread Fran
Hi again, Justin

Thanks for that GREAT link. There is no case for spending time
breaking my head to solve problems that only occurs on 1.6 and below.

Thanks a million,


On May 10, 6:20 am, Justin Anderson  wrote:
> > May be I will nd up using API level 5... is there any place with stats
> > about SDK usage to know how many market I will lost in that case?
>
> According to this link, you will hit 99% of the devices out there if you
> target Android 2.1 or 
> newer...http://developer.android.com/resources/dashboard/platform-versions.html
>
> Thanks,
> Justin Anderson
> MagouyaWare Developerhttp://sites.google.com/site/magouyaware
>
>
>
>
>
>
>
> On Wed, May 9, 2012 at 1:14 PM, Fran  wrote:
> > Hi Justin,
>
> > Nice to read you again. I think you have miss understood me, probably
> > cause I did not explain myself right neither: my English is not the
> > best one exactly...
>
> > The method linked by Jason uses onBackPressed() ONLY, so what I meant
> > is that I cannot use that method if I want to kept backward
> > compatibility, so I need to use the other one proposed by you that
> > relies on onKeyDown. Yes, it also uses onBackPressed, but I though it
> > was clear what i wanted to say just pasting the first lines of code of
> > each proposed solution.
>
> > Anyway It works fine in my Samsung GS2, and also in a 2.1 emulator,
> > but it does not on a 1.6 emulator. At least not with my code.
>
> > Both versions calls to onBackPressed as expected, but while on 2.1+
> > Android does not close the application after that call, in 1.6 it does
> > it.
>
> > I have also additional problems with this: when I try to get back from
> > pause on 1.6, the application crashes, but it still works fine in
> > 2.1+.
>
> > May be I will nd up using API level 5... is there any place with stats
> > about SDK usage to know how many market I will lost in that case?
>
> > Best regards and thanks again by your help,
>
> > On May 8, 5:12 pm, Justin Anderson  wrote:
> > > > Thanks a lot Jason and Justin. My game works fine on 1.6+, at least on
> > > > simulator. AFAIK that's API level 4, so I cannot use this method if I
> > > > wan to keep that compatibility:
>
> > > > @Override
> > > > public void onBackPressed() {
> > > >   return;
> > > > }
>
> > > That's not true... Set your target API level to something high enough
> > that
> > > you can use the onBackPressed.  Did you read the link I gave you?  It
> > > specifically addresses this and tells you how to use both depending on
> > the
> > > API level.
>
> > > Thanks,
> > > Justin Anderson
> > > MagouyaWare Developerhttp://sites.google.com/site/magouyaware
>
> > > On Tue, May 8, 2012 at 7:01 AM, Fran  wrote:
> > > > Thanks a lot Jason and Justin. My game works fine on 1.6+, at least on
> > > > simulator. AFAIK that's API level 4, so I cannot use this method if I
> > > > wan to keep that compatibility:
>
> > > > @Override
> > > > public void onBackPressed() {
> > > >   return;
> > > > }
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Confirmation with pressing back button

2012-05-09 Thread Justin Anderson
>
> May be I will nd up using API level 5... is there any place with stats
> about SDK usage to know how many market I will lost in that case?
>

According to this link, you will hit 99% of the devices out there if you
target Android 2.1 or newer...
http://developer.android.com/resources/dashboard/platform-versions.html


Thanks,
Justin Anderson
MagouyaWare Developer
http://sites.google.com/site/magouyaware


On Wed, May 9, 2012 at 1:14 PM, Fran  wrote:

> Hi Justin,
>
> Nice to read you again. I think you have miss understood me, probably
> cause I did not explain myself right neither: my English is not the
> best one exactly...
>
> The method linked by Jason uses onBackPressed() ONLY, so what I meant
> is that I cannot use that method if I want to kept backward
> compatibility, so I need to use the other one proposed by you that
> relies on onKeyDown. Yes, it also uses onBackPressed, but I though it
> was clear what i wanted to say just pasting the first lines of code of
> each proposed solution.
>
> Anyway It works fine in my Samsung GS2, and also in a 2.1 emulator,
> but it does not on a 1.6 emulator. At least not with my code.
>
> Both versions calls to onBackPressed as expected, but while on 2.1+
> Android does not close the application after that call, in 1.6 it does
> it.
>
> I have also additional problems with this: when I try to get back from
> pause on 1.6, the application crashes, but it still works fine in
> 2.1+.
>
> May be I will nd up using API level 5... is there any place with stats
> about SDK usage to know how many market I will lost in that case?
>
> Best regards and thanks again by your help,
>
>
> On May 8, 5:12 pm, Justin Anderson  wrote:
> > > Thanks a lot Jason and Justin. My game works fine on 1.6+, at least on
> > > simulator. AFAIK that's API level 4, so I cannot use this method if I
> > > wan to keep that compatibility:
> >
> > > @Override
> > > public void onBackPressed() {
> > >   return;
> > > }
> >
> > That's not true... Set your target API level to something high enough
> that
> > you can use the onBackPressed.  Did you read the link I gave you?  It
> > specifically addresses this and tells you how to use both depending on
> the
> > API level.
> >
> > Thanks,
> > Justin Anderson
> > MagouyaWare Developerhttp://sites.google.com/site/magouyaware
> >
> >
> >
> >
> >
> >
> >
> > On Tue, May 8, 2012 at 7:01 AM, Fran  wrote:
> > > Thanks a lot Jason and Justin. My game works fine on 1.6+, at least on
> > > simulator. AFAIK that's API level 4, so I cannot use this method if I
> > > wan to keep that compatibility:
> >
> > > @Override
> > > public void onBackPressed() {
> > >   return;
> > > }
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Confirmation with pressing back button

2012-05-09 Thread Fran
Hi Justin,

Nice to read you again. I think you have miss understood me, probably
cause I did not explain myself right neither: my English is not the
best one exactly...

The method linked by Jason uses onBackPressed() ONLY, so what I meant
is that I cannot use that method if I want to kept backward
compatibility, so I need to use the other one proposed by you that
relies on onKeyDown. Yes, it also uses onBackPressed, but I though it
was clear what i wanted to say just pasting the first lines of code of
each proposed solution.

Anyway It works fine in my Samsung GS2, and also in a 2.1 emulator,
but it does not on a 1.6 emulator. At least not with my code.

Both versions calls to onBackPressed as expected, but while on 2.1+
Android does not close the application after that call, in 1.6 it does
it.

I have also additional problems with this: when I try to get back from
pause on 1.6, the application crashes, but it still works fine in
2.1+.

May be I will nd up using API level 5... is there any place with stats
about SDK usage to know how many market I will lost in that case?

Best regards and thanks again by your help,


On May 8, 5:12 pm, Justin Anderson  wrote:
> > Thanks a lot Jason and Justin. My game works fine on 1.6+, at least on
> > simulator. AFAIK that's API level 4, so I cannot use this method if I
> > wan to keep that compatibility:
>
> > @Override
> > public void onBackPressed() {
> >   return;
> > }
>
> That's not true... Set your target API level to something high enough that
> you can use the onBackPressed.  Did you read the link I gave you?  It
> specifically addresses this and tells you how to use both depending on the
> API level.
>
> Thanks,
> Justin Anderson
> MagouyaWare Developerhttp://sites.google.com/site/magouyaware
>
>
>
>
>
>
>
> On Tue, May 8, 2012 at 7:01 AM, Fran  wrote:
> > Thanks a lot Jason and Justin. My game works fine on 1.6+, at least on
> > simulator. AFAIK that's API level 4, so I cannot use this method if I
> > wan to keep that compatibility:
>
> > @Override
> > public void onBackPressed() {
> >   return;
> > }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Confirmation with pressing back button

2012-05-08 Thread Justin Anderson
>
> Thanks a lot Jason and Justin. My game works fine on 1.6+, at least on
> simulator. AFAIK that's API level 4, so I cannot use this method if I
> wan to keep that compatibility:
>
> @Override
> public void onBackPressed() {
>   return;
> }
>

That's not true... Set your target API level to something high enough that
you can use the onBackPressed.  Did you read the link I gave you?  It
specifically addresses this and tells you how to use both depending on the
API level.

Thanks,
Justin Anderson
MagouyaWare Developer
http://sites.google.com/site/magouyaware


On Tue, May 8, 2012 at 7:01 AM, Fran  wrote:

> Thanks a lot Jason and Justin. My game works fine on 1.6+, at least on
> simulator. AFAIK that's API level 4, so I cannot use this method if I
> wan to keep that compatibility:
>
> @Override
> public void onBackPressed() {
>   return;
> }
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Confirmation with pressing back button

2012-05-08 Thread Fran
Thanks a lot Jason and Justin. My game works fine on 1.6+, at least on
simulator. AFAIK that's API level 4, so I cannot use this method if I
wan to keep that compatibility:

@Override
public void onBackPressed() {
   return;
}

So I will use the keyevent based method (JFTR again):

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)  {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() ==
0) {
// do something on back.
return true;
}

return super.onKeyDown(keyCode, event);
}


On 7 mayo, 18:46, Justin Anderson  wrote:
> Depending on the version of Android you are targeting, this will also be
> very 
> helpful:http://android-developers.blogspot.com/2009/12/back-and-other-hard-ke...
>
> Thanks,
> Justin Anderson
> MagouyaWare Developerhttp://sites.google.com/site/magouyaware
>
>
>
>
>
>
>
> On Mon, May 7, 2012 at 7:28 AM, Jason Teagle  wrote:
> >  One of these is that when the user press the back button of the phone -
> >> I mean that with a curved arrow-, the application is closed, so I want
> >> to ask for confirmation or something similar so, is there anyway to
> >> easy control this?
>
> > I believe this link will help you considerably:http://stackoverflow.com/*
> > *questions/4779954/disable-**back-button-in-android
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to 
> > android-developers@**googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+**unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/**group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Confirmation with pressing back button

2012-05-07 Thread lbendlin
Most users press the back button for a reason. They may not take it 
gracefully when they get patronized "Are you really sure?". It may be 
easier for you to just take the appropriate action in your game (save the 
state, suspend the game).

On Monday, May 7, 2012 9:24:17 AM UTC-4, Fran wrote:
>
> Hi there, 
>
> I am writing my first Android game. I have following the Mario 
> Zechner's book "Begining Android Games" that I have found very useful 
> to quick introduce in this world. In the first middle of his book his 
> proposes a basic framework that I am using, that uses just one 
> activity for all the game. This approach is perfect for my needs in 
> this first game, and everything is working fine but some little 
> problems. 
>
> One of these is that when the user press the back button of the phone - 
> I mean that with a curved arrow-, the application is closed, so I want 
> to ask for confirmation or something similar so, is there anyway to 
> easy control this? 
>
> Thanks a lot in advance, 
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en