Still in the depths of the screen orientation change learning curve. Trying to save all the dynamic views in an Activity, so that I can restore them in Activity_Resume.
I am surprised that I have not been able to find a good example of handling a rotation in the forum. I have spent hours looking. I am probably making this too hard. Finally found something I like better about iOS than Android.
I am testing this on my Main layout. The layout has three ImageViews. In the code below, the ImageBiew.Bitmap is always null, even though the IV has a width and height. I can see the images on the screen before rotating the device. Here is the code:
Log Stuff:
** Activity (main) Pause, UserClosed = false **
Type = anywheresoftware.b4a.BALayout
Tag =
Type = android.widget.ImageView
Tag = ivCustLogo
v is ImageView
bm W = 75 bm H = 57
java.lang.NullPointerException: Attempt to invoke virtual method 'byte[] anywheresoftware.b4a.randomaccessfile.B4XSerializator.ConvertObjectToBytes(java.lang.Object)' on a null object reference
[...]
bitmap is null
Saved ImageView 1
Type = android.widget.TextView
Tag =
Type = android.widget.TextView
Tag =
Type = android.widget.ImageView
Tag = iStartCustomer
v is ImageView
bm W = 852 bm H = 480
bitmap is null
Saved ImageView 4
Type = de.amberhome.objects.internal.InternalToolbar
Tag =
Type = android.widget.TextView
Tag =
Type = android.widget.TextView
Tag =
Type = android.widget.TextView
Tag =
Type = android.widget.ImageView
Tag = ivLogo
v is ImageView
bm W = 125 bm H = 125
bitmap is null
Saved ImageView 9
Main Activity_Resume
I am surprised that I have not been able to find a good example of handling a rotation in the forum. I have spent hours looking. I am probably making this too hard. Finally found something I like better about iOS than Android.
I am testing this on my Main layout. The layout has three ImageViews. In the code below, the ImageBiew.Bitmap is always null, even though the IV has a width and height. I can see the images on the screen before rotating the device. Here is the code:
B4X:
Sub Activity_Pause (UserClosed As Boolean)
Wait For (SaveState(Activity)) complete (Result As Int)
End Sub
Public Sub SaveState(inActivity As Activity) As ResumableSub
For i = 0 To inActivity.NumberOfViews - 1
Dim v As View = inActivity.GetView(i)
Log("Type = " & GetType(v))
Log("Tag = " & v.Tag)
If v Is ImageView Then
Log("v is ImageView")
Dim iv As ImageView = v
If iv.IsInitialized Then
Dim bm As Bitmap = iv.Bitmap
Log("bm W = " & bm.Width & " bm H = " & bm.Height)
Try
Starter.kvs.PutBitmap("imageview",bm)
Catch
Log("bitmap is null")
End Try
Log("Saved ImageView " & i)
End If
End If
Next
Return True
End Sub
Log Stuff:
** Activity (main) Pause, UserClosed = false **
Type = anywheresoftware.b4a.BALayout
Tag =
Type = android.widget.ImageView
Tag = ivCustLogo
v is ImageView
bm W = 75 bm H = 57
java.lang.NullPointerException: Attempt to invoke virtual method 'byte[] anywheresoftware.b4a.randomaccessfile.B4XSerializator.ConvertObjectToBytes(java.lang.Object)' on a null object reference
[...]
bitmap is null
Saved ImageView 1
Type = android.widget.TextView
Tag =
Type = android.widget.TextView
Tag =
Type = android.widget.ImageView
Tag = iStartCustomer
v is ImageView
bm W = 852 bm H = 480
bitmap is null
Saved ImageView 4
Type = de.amberhome.objects.internal.InternalToolbar
Tag =
Type = android.widget.TextView
Tag =
Type = android.widget.TextView
Tag =
Type = android.widget.TextView
Tag =
Type = android.widget.ImageView
Tag = ivLogo
v is ImageView
bm W = 125 bm H = 125
bitmap is null
Saved ImageView 9
Main Activity_Resume