How do I disable device back button in Android temporarily while the application is launching?

This thread was migrated from an old forum. It may contain information that are no longer valid. For further assistance, please post a new question or open a support ticket from the Customer Support portal.

Hi,

Do we have an FFI or NFI to disable the back button in splash?

Thanks.

For every kony application built there is an activity created with the application id as the class name in the package path same as package name of android application.

You can override onBackPressed() function in that generated activity

public void onBackPressed(){

//super.onBackPressed(); should not be called until first form is shown

super.onBackPressed();

return;

}

https://developer.android.com/reference/android/app/Activity.html#onBackPressed()

This can be done with andoridprecompiletask.xml

2nd thing that needs to be handled is "super.onBackPressed(); should not be called until first form is shown"

This should be done with some state passed to FFI from first form's preshow

Thanks for the reply. We also have onDeviceBack() when the first form is loaded. But is there no other way to stop back button while the application is in splash screen.

onDeviceBack() is kony exposed callback on Form

https://docs.kony.com/konyonpremises/Subsystems/Widget_User_Guide/Content/Form_Events.htm#onDevice

onBackPressed() is the native android activity level callback which I have mentioned.

This helps achieve your usecase as both splash screen a well as Form are rendered in same activity.

Framework overrides onBackPressed() in KonyMain to support onDeviceBack() event on Form.

You can do the same in the Activity auto generated which extends KonyMain as specified in my previous response to achieve overriding back key in splash screen.

I did override the function and the code is executed. However the application also goes to background. What am I doing wrong?

  1. public class BackPressed extends Activity {
  2. @Override
  3. public void onBackPressed() {
  4. KonyMain context = KonyMain.getActivityContext();
  5. if (context != null) {
  6. Toast.makeText(context, "Back is pressed", 1).show();
  7. }
  8. // super.onBackPressed();
  9. }
  10. }

"BackPressed extends Activity" Is this in a Kony Quantum app ?

Are you displaying this new activity ?

Back key suppression would only limit to the BackPressed activity.

In order to handle for Kony Quantum forms, as i said previously,

for every Kony Quantum application built there is an activity created with the application id as the class name in the package path same as package name of android application.

You should override onBackPressed() function in that generated activity not in any arbitrary activity.