it seems that overrriding onKeyDown() method of your activity and
returning with a true value perhaps may serve your need.


On Jun 29, 8:42 am, "draf...@gmail.com" <draf...@gmail.com> wrote:
> I currently have an Activity that when it gets displayed a
> Notification will also get displayed in the Notification bar.
>
> This is so that when the User presses home and the Activity gets
> pushed to the background they can get back to the Activity via the
> Notification.
>
> The problem arises when a User presses the back button, my Activity
> gets destroyed but the Notification remains as I want the user to be
> able to press back but still be able to get to the Activity via the
> Notification. But when a USER tries this I get Null Pointers as its
> trying to start a new activity rather than bringing back the old one.
>
> So essentially I want the Back button to act the exact same as the
> Home button and here is how I have tried so far:
>
> ---
>
>                         @Override
>                         public boolean onKeyDown(int keyCode, KeyEvent event) 
>  {
>                             if 
> (Integer.parseInt(android.os.Build.VERSION.SDK) < 5
>                                     && keyCode == KeyEvent.KEYCODE_BACK
>                                     && event.getRepeatCount() == 0) {
>                                 Log.d("CDA", "onKeyDown Called");
>                                 onBackPressed();
>                             }
>
>                             return super.onKeyDown(keyCode, event);
>                         }
>
>                         public void onBackPressed() {
>                                 Log.d("CDA", "onBackPressed Called");
>                         Intent setIntent = new Intent(Intent.ACTION_MAIN);
>                         setIntent.addCategory(Intent.CATEGORY_HOME);
>                         setIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
>                         startActivity(setIntent);
>
>                             return;
>                         }
>
> ---
>
> However the above code still seems to allow my Activity to be
> destroyed, How can I stop my Activity from being destroyed when the
> back button is pressed?

-- 
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

Reply via email to