on 10-27-2018 10:02 AM
I'm following the beginner tutorial and I've applied the "Enable Offline OData in Your Android Application" step to my Customers.
If you enter the application and click fast on Customer (at the very start) it gets you this error:
with the following stack trace:
E/com.sap.wizapp.data.operation.AbstractOnODataOperations: [main] SAPServiceManager was not initialized
E/com.sap.wizapp.app.ErrorPresenterByNotification: [SAPWizardErrorHandler] Download failed: Download operation failed, please try to restart the application.java.lang.IllegalStateException: SAPServiceManager was not initialized
at com.sap.wizapp.service.SAPServiceManager.getESPMContainer(SAPServiceManager.java:128)
at com.sap.wizapp.data.operation.DownloadOperation.execute(DownloadOperation.java:53)
at com.sap.wizapp.data.DataContentUtilities.download(DataContentUtilities.java:100)
at com.sap.wizapp.mdui.ItemListActivity.onResume(ItemListActivity.java:107)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1412)
at android.app.Activity.performResume(Activity.java:7292)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3776)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3816)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
To solve this issue (at least this is, in my opinion, the correct solution) is to change the code inside into the SAPServiceManager.java for these two functions: openODataStore and setupOfflineOData.
inside the setupOfflineOData add the Action0 callback as a parameter and call the callback.call() only after you have correctly initialized the ESPMContainer.
inside the openODataStore remove the call to the callback.call() and pass the callback to the setupOfflineOData
This is the complete code
public void openODataStore(Action0 callback, Context context) {
setupOfflineOData(callback, context);
}
private void setupOfflineOData(Action0 callback, Context context) {
try {
if (configurationData.loadData()) {
//Initialize application context for use by OfflineODataProvider
AndroidSystem.setContext(context);
//commonly set parameters include setStoreEncryptionKey, setStoreName, setStorePath
OfflineODataParameters offParam = new OfflineODataParameters();
String serviceUrl = configurationData.getServiceUrl();
URL url = new URL(serviceUrl + CONNECTION_ID_ESPMCONTAINER);
provider = new OfflineODataProvider(url, offParam, ClientProvider.get());
//Specifies which entities we wish to include in the offline store
provider.addDefiningQuery(new OfflineODataDefiningQuery("Customers", "Customers", false));
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (OfflineODataException e) {
e.printStackTrace();
}
//opens the offline store. This can take a minute or so the first time it is called as it is created and populated.
Log.d(TAG, "About to call open on the offline store.");
provider.open(() -> {
Log.d(TAG, "Offline store opened.");
eSPMContainer = new ESPMContainer(provider);
callback.call();
syncOfflineData(); //TODO could be triggered via a menu action
}, (OfflineODataException offlineODataException) -> {
Log.d(TAG, "Offline store did not open.", offlineODataException);
});
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Nicely done! Is there code that needs to be updated in the tutorial?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Note, I would recommend taking a look at the following tutorial series. The one referenced above is for TechEd only.
https://developers.sap.com/sea/group.sdk-android.html
Another one to take a look at is
https://blogs.sap.com/2018/10/15/step-by-step-with-the-sap-cloud-platform-sdk-for-android-part-1/
Thanks for your feedback. The tutorial has been updated.
Regards,
Dan van Leeuwen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
By the way ericci this is the best way to get questions answered. If you feel like you're not getting the attention you need - you know how to send me a PM on Twitter!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.