Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23444] Android: Showing a DialogFragment throws "Can not perform this action after onSaveInstanceState" error

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionCannot Reproduce
Resolution Date2019-10-17T21:24:29.000+0000
Affected Version/sRelease 5.2.2
Fix Version/sn/a
ComponentsAndroid
Labelsandroid, fragments, modal, module
ReporterDavid Vermeir
AssigneeUnknown
Created2016-05-23T15:16:44.000+0000
Updated2019-10-17T21:24:29.000+0000

Description

Problem

Hi, I'm creating an Android and iOS module for Titanium which has a sendLog method which sends some arbitrary JSON data to a server and returns an URL if it matches some predefined filters. The URL should be opened in a modal Dialog with a webview. I've written native iOS and Android libraries and wrapped them as Titanium modules. On iOS everything works fine but on Android I can't open the Dialog (see error stack trace below). Right now there's one log message that always triggers the same webpage for testing purposes. On Android it just fails silently.

Test case

var mupets = require("be.iminds.mupets");
mupets.initialize("wappr", "http://tocker.iminds.be:3000/log/report.json", 1, 100, 3);
var esmLog = { 
	bar: "foo"
};
mupets.sendLog("es-test-01",JSON.stringify(esmLog));
After this piece of code (after about 10 seconds max), the module should show a native dialog with the following webpage inside: http://tocker.iminds.be:3000/es/sheets/test-01/index.html Instead, this is the error I get consistently:

Logs

java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1411)
at android.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1429)
at android.app.BackStackRecord.commitInternal(BackStackRecord.java:687)
at android.app.BackStackRecord.commit(BackStackRecord.java:663)
at android.app.DialogFragment.show(DialogFragment.java:256)
at be.iminds.mupets_client_android.logging.plugins.OutHttp.getEsm(OutHttp.java:122)
at be.iminds.mupets_client_android.logging.plugins.OutHttp$1.success(OutHttp.java:78)
at be.iminds.mupets_client_android.HttpClient$1$1.onResponse(HttpClient.java:76)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:133)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Here is the Android code that's causing the error:
Activity activity = (Activity) context;
                EsmDialogFragment esmDialogFragment = EsmDialogFragment.newInstance(new EsmDialogListener() {
                    @Override
                    public void submit(String type, JsonObject result) {
                        Mupets.sendLog(type, result);
                        esmShown = false;
                    }

                    @Override
                    public void onCancel(JsonObject cancelled) {
                        super.onCancel(cancelled);
                        Mupets.sendLog("ESM_cancelled", cancelled);
                        esmShown = false;
                    }
                }, url, true);
                FragmentTransaction transaction = activity.getFragmentManager().beginTransaction();
                Fragment prev = activity.getFragmentManager().findFragmentByTag(EsmDialogFragment.ESM_DIALOG_FRAGMENT);
                if (prev != null) {
                    transaction.remove(prev);
                }
                transaction.addToBackStack(null);
                Log.v(TAG, "Pre-show fragment");
                esmDialogFragment.show(transaction, EsmDialogFragment.ESM_DIALOG_FRAGMENT);
                Log.v(TAG, "Post-show fragment");
Does Titanium either not allow the use of Fragments/or require you to call Dialog.show() at a specific point? The error talks about "...after onSaveInstanceState" but I don't see how I would call it before onSaveInstanceState if I'm not creating an activity and why the code works when I use it in a native Android app. I added the Android module and iOS module I use to this ticket.

Attachments

FileDateSize
be.iminds.mupets-android-1.0.2.zip2016-05-23T15:17:24.000+0000653675
be.iminds.mupets-iphone-1.0.2.zip2016-05-23T15:18:13.000+00007355503

Comments

  1. Nazmus Salahin 2016-05-24

    Hello [~Ventis], Thanks for reaching out. I did install the android module you provided but it is not recognized by accelerator studio although install was successful. Will you please make sure that you provide the right file and it works. Thanks in advance
  2. David Vermeir 2016-05-24

    Hi Nazmus Salahin, I'm using this module in my project and it's recognized fine. Can you tell me what the problem exactly is? Kind regards, David
  3. Nazmus Salahin 2016-05-24

    Dear David, The module is not recognized by tiapp.xml. Plsease let me know min SDK version for using the module and which SDK version did you use for build ? Regards
  4. David Vermeir 2016-05-24

    Hi, the minSDK for the module is 5.2.0.GA and the SDK I used is 5.2.2.GA.
  5. David Vermeir 2016-05-24

    I have a test project with the module that I could give you but it's 11MB which is larger than the max file size on this ticket.
  6. David Vermeir 2016-05-24

    Here's a link to the test project I mentioned earlier: https://www.dropbox.com/s/0v77xd5gllv6kb3/testModule.zip?dl=1
  7. Sharif AbuDarda 2016-05-24

    Hello, The example project you have set it also not configuring your module, in our environment. Importing your project into our studio is not showing the module configured in our environment. We are using SDK 5.2.2.GA for test. It's necessary for us to test the issue. Regards, Sharif.
  8. David Vermeir 2016-05-25

    I created this example project specially for this ticket in a completely new environment and it works fine. I don't understand the problems you are having with it. I'm using 5.2.2.GA just like you... The module I provided is just the output of a normal Titanium module project. The example project is a Titanium mobile project I zipped myself. Please tell me the necessary steps I need to perform so it will work for you.
  9. Nazmus Salahin 2016-05-26

    Hello, Here is what happening in my environment. The module is not recognised by tiapp.xml but the projects runs. [Screenshot Link](https://i.imgsafe.org/6e7b08d.png) When I run the given code portion the app crash with a different error log. *Code:*
       var mupets = require("be.iminds.mupets");
       
       var win = Ti.UI.createWindow({
       	backgroundColor : 'white'
       });
       var label = Titanium.UI.createLabel({
       	color:'#999',
       	text:'RUN',
       	font:{fontSize:20,fontFamily:'Helvetica Neue'},
       	textAlign:'center',
       	width:'auto'
       });
       
       label.addEventListener("click", function(e) {
       	Ti.API.info("clicked label");
       	
       	mupets.initialize("wappr", "http://tocker.iminds.be:3000/log/report.json", 1, 100, 3);
       
       	var esmLog = {
       
       		bar : "foo"
       
       	};
       
       	mupets.sendLog("es-test-01", JSON.stringify(esmLog));
       
       });
       win.add(label);
       win.open();
       
    *Error Log:*
       [INFO] :   clicked label
       [WARN] :   ResourceType: Bad XML block: header size 18254 or total size 169478669 is larger than data size 297
       [ERROR] :  TiApplication: (main) [2445,15989] Sending event: exception on thread: main msg:android.content.res.Resources$NotFoundException: File res/drawable-xhdpi-v4/abc_ab_share_pack_mtrl_alpha.9.png from xml type layout resource ID #0x7f020000; Titanium 5.2.2,2016/03/28 14:12,b685ddb
       [ERROR] :  TiApplication: android.content.res.Resources$NotFoundException: File res/drawable-xhdpi-v4/abc_ab_share_pack_mtrl_alpha.9.png from xml type layout resource ID #0x7f020000
       [ERROR] :  TiApplication: 	at android.content.res.Resources.loadXmlResourceParser(Resources.java:2821)
       [ERROR] :  TiApplication: 	at android.content.res.Resources.loadXmlResourceParser(Resources.java:2776)
       [ERROR] :  TiApplication: 	at android.content.res.Resources.getLayout(Resources.java:1165)
       [ERROR] :  TiApplication: 	at android.view.LayoutInflater.inflate(LayoutInflater.java:421)
       [ERROR] :  TiApplication: 	at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
       [ERROR] :  TiApplication: 	at be.iminds.mupets_client_android.esm.EsmDialogFragment.onCreateView(EsmDialogFragment.java:61)
       [ERROR] :  TiApplication: 	at android.app.Fragment.performCreateView(Fragment.java:2220)
       [ERROR] :  TiApplication: 	at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:973)
       [ERROR] :  TiApplication: 	at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148)
       [ERROR] :  TiApplication: 	at android.app.BackStackRecord.run(BackStackRecord.java:793)
       [ERROR] :  TiApplication: 	at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1535)
       [ERROR] :  TiApplication: 	at android.app.FragmentManagerImpl$1.run(FragmentManager.java:482)
       [ERROR] :  TiApplication: 	at android.os.Handler.handleCallback(Handler.java:739)
       [ERROR] :  TiApplication: 	at android.os.Handler.dispatchMessage(Handler.java:95)
       [ERROR] :  TiApplication: 	at android.os.Looper.loop(Looper.java:148)
       [ERROR] :  TiApplication: 	at android.app.ActivityThread.main(ActivityThread.java:5417)
       [ERROR] :  TiApplication: 	at java.lang.reflect.Method.invoke(Native Method)
       [ERROR] :  TiApplication: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
       [ERROR] :  TiApplication: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
       [ERROR] :  TiApplication: Caused by: java.io.FileNotFoundException: Corrupt XML binary file
       [ERROR] :  TiApplication: 	at android.content.res.AssetManager.openXmlAssetNative(Native Method)
       [ERROR] :  TiApplication: 	at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:485)
       [ERROR] :  TiApplication: 	at android.content.res.Resources.loadXmlResourceParser(Resources.java:2803)
       [ERROR] :  TiApplication: 	... 18 more
       [INFO] :   Process: Sending signal. PID: 5828 SIG: 9
       
       
    *Environment*: *Device info:* Nexus7 (android 6.0.1) *Node.js Version:* 0.12.7 *npm Version:* 2.11.3 *Titanium SDKs:* 5.2.2.GA *Java Development Kit Version:* 1.8.0_73 *Titanium CLI Version:* 5.0.5 *Appcelerator CLI Version:* 5.2.2 *Appcelerator Studio:* 4.5.0
  10. David Vermeir 2016-05-26

    That seems to happen because my library has a dependency on com.android.support:appcompat-v7:23.3.0 but I can't add it as a dependency because then I get the following errors:
        [ERROR] :  Failed to run dexer:
        [ERROR] :  
        [ERROR] :  Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v7/appcompat/R;
        [ERROR] :  Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v7/appcompat/R$anim;
        [ERROR] :  Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v7/appcompat/R$attr;
        [ERROR] :  Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v7/appcompat/R$bool;
        [ERROR] :  Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v7/appcompat/R$color;
        [ERROR] :  Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v7/appcompat/R$dimen;
        [ERROR] :  Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v7/appcompat/R$drawable;
        [ERROR] :  Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v7/appcompat/R$id;
        [ERROR] :  Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v7/appcompat/R$integer;
        [ERROR] :  
        [ERROR] :  UNEXPECTED TOP-LEVEL EXCEPTION:
        [ERROR] :  java.lang.RuntimeException: Translation has been interrupted
        [ERROR] :  	at com.android.dx.command.dexer.Main.processAllFiles(Main.java:608)
        [ERROR] :  	at com.android.dx.command.dexer.Main.runMonoDex(Main.java:311)
        [ERROR] :  	at com.android.dx.command.dexer.Main.run(Main.java:277)
        [ERROR] :  	at com.android.dx.command.dexer.Main.main(Main.java:245)
        [ERROR] :  	at com.android.dx.command.Main.main(Main.java:106)
        [ERROR] :  Caused by: java.lang.InterruptedException: Too many errors
        [ERROR] :  	at com.android.dx.command.dexer.Main.processAllFiles(Main.java:600)
        [ERROR] :  	... 4 more
        
  11. David Vermeir 2016-05-26

    Any ideas what this error message means?
  12. David Vermeir 2016-05-30

    Any update?
  13. Alan Hutton 2019-10-17

    Closing issue as “Cannot Reproduce”. We have tested the code provided, and found that it is out of date with our current release (8.2.0.GA as of the date of closure), and out of date with mobile OS versions. Updating the code may not reproduce the issue reported, or be a valid test case. If community members feel that the issue is still valid, please add a comment, and include code that demonstrates/reproduces the issue. Axway Appcelerator Studio, build: 5.1.4.201909061933  macOS : 10.15 Node.js Version : 8.9.1 npm Version : 5.5.1 Appcelerator CLI : 7.1.1 Titanium CLI CLI Version : 5.2.1 node-appc Version : 0.2.49 Titanium SDKs : 8.2.0.GA Pixel 3 Android API 29

JSON Source