0

I have a class that extended Application Class

I wondering if there is any way I could disable back button here?

mark
  • 53
  • 7
  • You cannot use `Application` context to build dialogs. – Gergely Kőrössy Mar 08 '17 at 00:26
  • I actually implement that part – mark Mar 08 '17 at 01:05
  • I just wondering how could I avoid user from pressing back button – mark Mar 08 '17 at 01:05
  • You can override `onBackPressed()` in your `Activity` or if you're talking about the dialog, just don't make it cancelable. – Gergely Kőrössy Mar 08 '17 at 02:23
  • But is there anyway I could disable in Application Class subclass but activity – mark Mar 08 '17 at 03:56
  • Since my class is not an activity – mark Mar 08 '17 at 03:57
  • I don't understand your question. The `Application` context represents *no possible UI interaction*, hence there's no such thing as suppressing back presses. What is your use case? What are you trying to achieve? I have a feeling that you don't understand the basic concepts of Android, such as `Activity` and `Application`. – Gergely Kőrössy Mar 08 '17 at 04:29
  • I have a Class say ClassA that extend Application when ClassA.oncreate called, it will check if new app version is availble and if it does, it will prompt a dialog with an button, and this is what i have implemented – mark Mar 08 '17 at 04:49
  • when user click that button, it will start an activity that do update on background and show update progress on UI and I have also implemented that activity – mark Mar 08 '17 at 04:50
  • but the thing is i want to prevent user from pressing back button right after dialog prompt in my Class A that extend Application Class and since that is not an activity I couldn't override onBackPressed, and i was wondering if there anyway or workaround I could acheive the same purpose – mark Mar 08 '17 at 04:53
  • You should not display a dialog from a non-`Activity` class, I guess you hack with the dialog type by making it system dialog. If you do what I think, there's no solution for that, you cannot block the user from pressing back button. Is this what you're doing? If not, please include some code in your question. – Gergely Kőrössy Mar 08 '17 at 05:40
  • @mark Maybe you could use an Activity that isn't full screen to act as the dialog. (I forget which theme you need.) Then you can override `onBackPressed()` in the activity to handle/ignore the back button press. – ban-geoengineering Mar 08 '17 at 11:22

0 Answers0