cancel
Showing results for 
Search instead for 
Did you mean: 

Download Failed: download operation failed, please try to restart the application

ericci
Active Contributor
0 Kudos

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)

ericci
Active Contributor
0 Kudos

daniel.vanleeuwen is there a way to submit directly feedback/issue on the tutorial itself? Also which should be the developer advocate to contact to start a discussion about feedback/improvements?

Accepted Solutions (1)

Accepted Solutions (1)

ericci
Active Contributor
0 Kudos

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);
    });
}

Answers (3)

Answers (3)

BWomelsdorf
Advisor
Advisor

Nicely done! Is there code that needs to be updated in the tutorial?

ericci
Active Contributor
0 Kudos

yes, I can I create a PR?

Dan_vL
Product and Topic Expert
Product and Topic Expert
0 Kudos

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

ericci
Active Contributor
0 Kudos

Hi Dan, I've already finished those tutorial as soon as I got home from the Teched BCN 😄

I'm starving for new sample and contents 😛

BWomelsdorf
Advisor
Advisor
0 Kudos

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!