Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] StageText doesn't work with <runtimeInBackgroundThread>true</runtimeInBackgroundThread> #2615

Closed
itlancer opened this issue Apr 21, 2023 · 6 comments

Comments

@itlancer
Copy link

Problem Description

StageText doesn't work with <runtimeInBackgroundThread>true</runtimeInBackgroundThread> for Android.
Text fields just doesn't show.

Tested with latest AIR 50.2.2.3 and AIR 50.2.2.4 versions with multiple different Android devices with different OS versions with different applications and architectures.
Same problem in all cases.
There is no such problem without <runtimeInBackgroundThread>true</runtimeInBackgroundThread>.

May be related issue:
#2614

Steps to Reproduce

Launch application with code below. It just display StageText.

Application example with sources attached.
android_runtimeinbackgroundthread_stagetext_bug.zip

package {
	import flash.display.Sprite;
	import flash.text.StageText;
	import flash.geom.Rectangle;
	import flash.events.FocusEvent;
	
	public class AndroidRuntimeInBackgroundThreadStageTextBug extends Sprite {
		
		public function AndroidRuntimeInBackgroundThreadStageTextBug() {
			var stageText:StageText = new StageText();
			stageText.fontSize = 72;
			stageText.text = "StageTextField";
			stageText.viewPort = new Rectangle(200, 200, 600, 100);
			stageText.stage = stage;
			stageText.visible = true;
			stageText.addEventListener(FocusEvent.FOCUS_IN, focusIn);
		}
	
		public function focusIn(e:FocusEvent):void {
			trace("focusIn");
		}
	}
}

Actual Result:
StageText not displayed.
With ADB Logcat you can see error log:

W/System.err: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
W/System.err:     at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:9629)
W/System.err:     at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:1919)
W/System.err:     at android.view.View.requestLayout(View.java:26296)
W/System.err:     at android.view.View.requestLayout(View.java:26296)
W/System.err:     at android.view.View.requestLayout(View.java:26296)
W/System.err:     at android.view.View.requestLayout(View.java:26296)
W/System.err:     at android.view.ViewGroup.addView(ViewGroup.java:5075)
W/System.err:     at android.view.ViewGroup.addView(ViewGroup.java:5017)
W/System.err:     at android.view.ViewGroup.addView(ViewGroup.java:4989)
W/System.err:     at com.adobe.air.AndroidActivityWrapper.getOverlaysLayout(AndroidActivityWrapper.java:781)
W/System.err:     at com.adobe.air.AndroidStageText.addToStage(AndroidStageText.java:696)
W/System.err:     at com.adobe.air.Entrypoints.EntryMainWrapper(Native Method)
W/System.err:     at com.adobe.air.Entrypoints.run(Entrypoints.java:275)
W/System.err:     at java.lang.Thread.run(Thread.java:1012)

Expected Result:
StageText will be shown. Input via soft keyboard and events works correctly.

Known Workarounds

  1. Do not use <runtimeInBackgroundThread>true</runtimeInBackgroundThread>.
  2. Use TextField but it has a lot of issues for mobile platforms with soft keyboard and some other functionalities:
    TextField is not correctly positioned when the softKeyboard is open on Pixel 7 Pro #2245
    [Android x86_64] Moving TextField cause it disappearing #967
    [Android] [Bug] Stage is not properly shifted to align Textfield input with keyboard #443
    TextField hide by Softkeyboard in full-screen mode #423
    Device soft keyboard doesn't appear when focusing on an input textfield in AIR33 with partial input method #255
    Device soft keyboard doesn't appear when focusing on an input textfield in AIR33.0.2.246 #109
@marchbold
Copy link
Collaborator

Confirmed this issue is happening with 50.2.2.6 as well

@itlancer
Copy link
Author

itlancer commented Aug 3, 2023

@ajwfrost
Checked with AIR SDK 50.2.3.1.
Now StageText displayed but after interacting with it (focus on it) all stage render "stops". DisplayList objects on Stage doesn't update anymore, Scout session stops and you cannot interract with any other objects but StageText.
It happens with multiple Android devices (but not all).

I made modified sample with StageText, TextField and square graphics (which rotated each frame):

package {
	import flash.display.Sprite;
	import flash.text.StageText;
	import flash.geom.Rectangle;
	import flash.events.FocusEvent;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	
	public class AndroidRuntimeInBackgroundThreadStageTextBug extends Sprite {
		private var sprite:Sprite = new Sprite();
		private var stageText:StageText = new StageText();
		private var textField:TextField = new TextField();
		
		public function AndroidRuntimeInBackgroundThreadStageTextBug() {
			stageText.fontSize = 42;
			stageText.text = "StageTextField";
			stageText.viewPort = new Rectangle(200, 200, 200, 100);
			stageText.stage = stage;
			stageText.visible = true;
			stageText.addEventListener(FocusEvent.FOCUS_IN, focusIn);
			
			textField.type = TextFieldType.INPUT;
			var tf:TextFormat = textField.defaultTextFormat;
			tf.size = 42;
			textField.defaultTextFormat = tf;
			textField.wordWrap = true;
			textField.text = "TextField";
			textField.x = 500;
			textField.y = 200;
			textField.width = 200;
			textField.height = 100;
			addChild(textField);
			
			sprite.graphics.beginFill(0xff0000);
			sprite.graphics.drawRect(0, 0, 100, 100);
			sprite.graphics.endFill();
			sprite.x = 100;
			sprite.y = 100;
			addChild(sprite);
			
			addEventListener(Event.ENTER_FRAME, enterFrame);
		}
		
		public function focusIn(e:FocusEvent):void {
			trace("focusIn");
		}
		
		public function enterFrame(e:Event):void {
			sprite.rotation += 1;
		}
	}
}

After click on StageText all render "stops" and application "hangs".
ADB Logcat:

D/CoreBackPreview: Window{258967 u0 Splash Screen android.runtimeinbackgroundthread.stagetext.bug EXITING}: Setting back callback null
W/InputManager-JNI: Input channel object '258967 Splash Screen android.runtimeinbackgroundthread.stagetext.bug (client)' was disposed without first being removed with the input manager!
D/ContentCapturePerUserService: Notified activity assist data for activity: Token{307f8b ActivityRecord{c04d868 u0 android.runtimeinbackgroundthread.stagetext.bug/.AIRAppEntry} t61363}} without a session Id
I/GoogleInputMethodService: GoogleInputMethodService.onStartInput():1902 onStartInput(EditorInfo{EditorInfo{packageName=android.runtimeinbackgroundthread.stagetext.bug, inputType=80001, inputTypeString=Normal, enableLearning=false, autoCorrection=false, autoComplete=true, imeOptions=12000006, privateImeOptions=null, actionName=DONE, actionLabel=null, initialSelStart=0, initialSelEnd=0, initialCapsMode=0, label=null, fieldId=-1, fieldName=null, extras=null, hintText=null, hintLocales=[]}}, false)
W/uhg: Infinite Data has no result for android.runtimeinbackgroundthread.stagetext.bug [CONTEXT service_id=177 ]
W/uhg: Infinite Data has no result for android.runtimeinbackgroundthread.stagetext.bug [CONTEXT service_id=177 ]

If you use only TextField - all fine.
Also all fine without <runtimeInBackgroundThread>true</runtimeInBackgroundThread>.

Issue reproduced with devices:
Sony Xperia 5 III, Android 13
Xiaomi Mi Note 10 Pro
Newland NQuire 1000 Manta II, Android 7.1
Projector ZHZ-M01, Android 5.1

But all fine with devices:
Samsung Galaxy A5, Android 8
Samsung A52, Android 12

@itlancer
Copy link
Author

@ajwfrost
Issue still exists with latest AIR SDK 50.2.3.3.

@bobaoapae
Copy link

@ajwfrost seems related to #2888

@itlancer
Copy link
Author

Issue still exists with latest AIR 50.2.4.1.

@itlancer
Copy link
Author

Fixed with latest AIR 50.2.4.2. Thanks!
But another one critical issue using <runtimeInBackgroundThread>true</runtimeInBackgroundThread> found: #3023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants