Android Question Different behavior with many activities on JB vs ICS

incendio

Well-Known Member
Licensed User
Longtime User
Hi guys,

I created a login form with something like these
B4X:
Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        Activity.LoadLayout("login")
    End If

End Sub

On Layout Login, there is a panel, name PnlLogin, with will be removed upon successful username and password
B4X:
Sub LoginBtn_Click
    PnlLogin.RemoveView
    LoginOk = True
    ReDrawMainLayout
End Sub

Codes for Activity_Resume
B4X:
Sub Activity_Resume
    Msgbox("Resume","")
    If(LoginOk = True) Then
        Msgbox("1","")
        ReDrawMainLayout
    End If
End Sub

And here is the ReDrawMainLayout codes
B4X:
Sub ReDrawMainLayout
    Activity.LoadLayout("main")
    ac2.Initialize("AC", ac2.VERTICAL)
     IsAcInitialized = True

     For i = 1 To 3
       Dim ai As AHActionItem
       Dim bd As BitmapDrawable
       Dim Filename, Text As String
     
       Select i
         Case 1       
           Filename = "Sales.png"
           Text = "Sales"
         Case 2
           Filename = "Browse.png"
           Text = "Browse"
         Case 3
           Filename = "Report.png"
           Text = "Reports"
       End Select

       bd.Initialize(LoadBitmap(File.DirAssets, Filename))
       ai.Initialize(i, Text, bd)
       ai.Selected = False

       ac2.addActionItem(ai)
     Next

End Sub

Here is the codes for menu item click
B4X:
Sub AC_Click (Position As Int, ActionItemID As Int)
    Dim Action As AHActionItem
    Action = ac2.getActionItem(Position)
   
    If(Action.Title = "Sales") Then
        StartActivity(Sales)
    Else If(Action.Title = "Report") Then
        StartActivity(Reports)
    Else If(Action.Title = "Browse") Then
        StartActivity(Browse)
    Else
        ToastMessageShow(Action.Title & " pressed", False)
    End If
End Sub

On Jellybean 4.2.2, app runs ok, but not with ICS.

On ICS, after start other activity, for ex, Sales, when user pressed Back Key, activity return to Main activity, Sub Activity_resume called (MsgBox Resume shows up), but Sub ReDrawMainLayout in that sub never called (MsgBox didn't show), so I got just a blank screen.
This is not the case with JB, Sub Activity_resume called and also Sub ReDrawMainLayout called.

Why is the result is different in ICS vs Jellybean?
Is there a way so that my codes work on all Android ver? Or how to better design login form?

Thanks in advance.
 

incendio

Well-Known Member
Licensed User
Longtime User
I am sorry if still have questions.
On JB, don't need to do that(probably because there is enough memory) but it is needed on my ICS.

So, it means, some how, ICS kill main activity, that is why var value is not retain, but this not a general rule.

On some ICS with enough memory, it could be that main activity not killed, so there is no need to save its value and restore it on Activity resume, and on JB with limited memory, var value must be save and restored it later, is that right?
 
Last edited:
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
You need to save your activity state. Period.
On JB, ICS, any version, any device, it is the standard procedure. Always.

The user may be using your app multitasking with many other apps, and this situation can happen on resuming it at any time. You can even make it happen on JB, if you use other apps and services in the middle and in the background.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
OK, I think I got it.

Just currious, If I declared var in process global, it doesn't need to save and restored it again and still have same effect, right?
 
Upvote 0
Top