cancel
Showing results for 
Search instead for 
Did you mean: 

MDK OnActivityBackPressed crashes on AssetManager 2210, MDK23.4.4, Android

oliver_kaluscha3
Participant
0 Kudos

I am running the following landscape:

SAP Service and Asset Manager 2210

MDK 23.4.4

Android

I have the following issue as well in the DEMO app on App store as well as on my custom branded client. So I suppose it is a general issue and I am wondering how I can fix this:

I am in demo mode. If you are on the main menu (OverView.page) and you open the list of all workorders, youi see the list. Fine. Now you press the back button of the android device (the one in the bottom right corner) and you are back on the main menu. So far so good.

But now you take the burger menu on the top left, (SideMenuDrawer.page)= and open all workorders. You see the list as well, but if you now press the hardware button in the bottom left corner, the app closes.

The reason is, that the SideMenuDrawer opens the page, but does not create an entry in the history. So there is no back button on top left corner, but you can open the burger menu again.

So I tried to implement the method OnActivityBackPressed but it closes the app first, then it does whatever code I have implemented. For example, if I tell this event to show a message and return false, so it shoudl stay on this page, it closes the app. If I open the app again, it shows my message and stays on the page.

Hopefully you can understand my issue.

How do I fix this?

If found this task: https://answers.sap.com/questions/13890286/cancel-modal-crashes-app-mdk-on-android.html

But even when I follow this, the issue for me does still exist.

What I need:OnActivityBackPressed and call an NavigationAction to open the OverView.page and clear history, it should open this page without closing the app.

Actually it does open the page, but it closes the app.

Thanx in advance,

Oliver

Accepted Solutions (0)

Answers (3)

Answers (3)

oliver_kaluscha3
Participant
0 Kudos

Hi,

I solved it. Reading the documentation did help..... Instead of calling the action directly in OnActivityBackPressed event. I call a rule. In this rule I set CANCEL to true for ClientAPI.getAppEventData(). This was mentioned in the documentation as well. After this was done, everything is working now as expected. Thanx a lot for your help!

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

As you mention, the design of the Asset Manager app provides two ways to navigate to the Work Orders list page.

  1. Direct navigation from the Overview page which adds Work Orders List to the nav stack. This opens the list and shows a back button to return to the Overview page.
  2. Open the Work Orders side drawer item. This creates a new nav stack starting with the Work Orders list page. There is no back button since it is the first page in the nav stack. Using the back button here will switch to the previous app / home screen since you are at the top level of the application. This is the expected behavior for Android apps as we have discussed above.

What is important here is that in both scenarios the Work Order List page is the same page definition just opened from a different starting point. MDK provides the OnActivityBackPressed event on Android to allow the developer to cancel the default back action and perform custom logic. In the first case you don't want to override the OnActivityBack event since the default behavior is what you want to occur.

In the second case, you will want to use a rule to cancel the default back action and then decide what should happen. Since it is the same page your rule will need to determine where is was opened from (check prev page or current drawer name) so it can handle both scenarios from the same rule. Rather than navigating back to the overview page you will need to decided if you really want to return to the overview from the drawer page or not. If yes, I would recommend just switching the drawer back to the Home drawer rather than changing the starting point for the Work Orders drawer.

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

When you select Work Orders from the Side Drawer it is not navigating from the Overview page to the Work Orders list page. Instead it is opening the Work Orders drawer which starts a separate Nav stack originating from the Work Orders list page. Each item in the Side Drawer is it's own Nav Stack. This is why there is no back button shown when you initially open the item from the Side Drawer.

All that said it definitely should not crash when you press back from the first page in a Side Drawer item. I will have to test and see if I can reproduce it.

oliver_kaluscha3
Participant
0 Kudos

Hi Bill,

thanx a lot for your answer. Yes, that all makes absolutely sense and it was my understanding of the process. Even that it closes the app is somehow understandable. If you are on the top page of your navigation stack and you press the back button of the device, it will open the main menu of the android device. So far so good.

I just would like to know why it crashes even when I implement the OnActivityBackPressed function. In my understanding, if I implement that function, it should prevent the system from doing its standard process and I could implement my own. Actually it does both - first it runs through the standard android process (and puts the app into the background) and then it runs through my implementation.

Or is my understanding of OnActivityBackPressed wrong?

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

As you mentioned the client isn't crashing but instead returning to the home screen which is consistent with other Android apps. If you are on the "main" page of any Android application and press the hardware back button the app returns to the previous app or to the home screen. I think this is considered the correct behavior.

Regarding the crash in your OnActivityBackPressed rule you would need to share the rule as I am unable to replicate the crash and it is working as expected for me.

oliver_kaluscha3
Participant
0 Kudos

Well, there is nothing special. Inside my Screen I call an action or a rule.

"OnActivityBackPressed": "/CIMIAssetManager/Actions/Navigation/NavToMainMenu.action",

This action should navigate to the main screen.

{
"_Type": "Action.Type.Navigation",
"PageToOpen": "/CIMAssetManager/Pages/MyOverview.page",
"ClearHistory": true
}

But as said: It first closes the app, then it navigates to the main screen. So if I open the app again, it shows the Custom OverView Page.

InterestingFact: there is a difference between the BackButton and the rule. I can open a page called WorkOrders from the OverView Page or from the side drawer. In both cases I get a list of orders and as we have seen, it is a difference in there. So If I open it from the OverviewPage, I have a history, opening it from the side drawer I do not have this history. So in the first case the back button goes back, in the second case the back button causes the app to close. This is clear, we have already spoken about it and it makes total sense to me.

If I add the OnActivityBackPressed to WorkOrders, the behaviour changes. I would expect, that it shows the MyOverview Page, but now in both cases the app closes and if I open it again I can see the MyOverview.page.

So if you say it works fine for you, there must be an error in the action - but there are only 3 lines of code.... what Do I do wrong here?

I did even start the app in DEBUG Mode and tested it for Uncaught Exceptions, but nothing was thrown.