Android Question [SOLVED] PreferenceActivity and Activity_Resume (not reached)

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,
I can not understand why in some cases when you return from the PreferenceScreen to the Activity, Activity_Resume is not reached.

I have noticed this on the Moto G and not on the Emulator. I'll have to make more tests with other devices. But I must admit that this questions my understanding.

Do you know why, please ? Thanks
 
Last edited:

lemonisdead

Well-Known Member
Licensed User
Longtime User
Yes Luca. I did and use PreferenceActivity since long time ago. I never noticed this behaviour.

I previously thought it was because I had some tasks not finished in the Activity_Resume's sub so I tried to reorder to put GetUpdatedKeys in first without more result. Than I reduced to one line to get GetUpdatedKeys but I do confirm that on the Moto G, the Activity_Resume is sometimes not reached when returning from PreferenceScreen, reason why I've posted the question.
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
I didn't took it bad, Luca :p I know you are a Gentleman
With this example, 1/2 half time I don't get a color change of the activity's background. I really can't understand how this works on this device : in DEBUG mode, I can see the Activity_Resume line but it seems to me that HandleSettings sub is not reached too. If I put a Log("Blabla") in Activity_Resume, I can't see the line printed too.
Well, I will try to reset the device to the factory settings. But it is a strange behaviour :)
 
Upvote 0

robotop

Member
Licensed User
Longtime User
Hello, just a (silly) question: is the Activity_Pause entered prior to that missing Activity_Resume ?
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello RobTop,

You were right and it is absolutely a good question, thanks. I did not thought about to try.
Here is the result : the Activity_Pause line is printed but as for the Activity_Resume, if I put a Log("Blabla") in it, it won't print (in DEBUG mode of course). That's really weird and again, it's working perfectly on the Emulator. I am lost.
 
Upvote 0

robotop

Member
Licensed User
Longtime User
Hello, may be the "log" action interferes in some way with the "limbo" state from pause to resume. May be you can try to save your personal log as text file on a working directory and then, after closing the activity (and experiment), you can look at this file, watching for events history. All multitasking states are difficult to trace when running on a simulator...
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,
Rapid followup : the idea of writing the log was good but was not working better. I have sent an e-mail to Support as I guess any other reply to be "consult a wizard" or "you don't understand how it works" ;-)
 
Upvote 0

robotop

Member
Licensed User
Longtime User
Hello, I think that consulting a wizard is always a good suggestion ; You can ask him for that question and also for your fortune ! :)
Anyway, if writing to a file in different parts of your program gives no results on the output file, may be that parts haven't been executed. If this is the behaviour, there must be some blocking process and this is very strange. Then... ok for the wizard.
Btw, have you used a flush for the output stream (in the test file) before closing it in the various parts of you program ?
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,
Yes I am sure not to flush. Below is my code and I am loosing my latin about. It works like a charm on some devices but not on the Moto G I had previously talked about...

This code needs those libraries : PreferenceActivity & RandomAccessFile
and

B4X:
#Region  Project Attributes
    #ApplicationLabel: TrapPref
    #VersionCode: 1
    #VersionName: 1
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals

End Sub

Sub Globals
    Dim prefManager As PreferenceManager
    Dim prefScreen As PreferenceScreen
    Dim Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Button1.Initialize("Btn1")
    Button1.Text="Open Pref"
    Activity.AddView(Button1,10%x,10%y,80%x,15%y)

    prefScreen.Initialize("Title","Some Prefs")
    CreatePrefs
End Sub

Sub Activity_Resume
    LogUpdatedKeys
    WriteMyActivity("Activity_Resume")

    If File.Exists(File.DirDefaultExternal,"LogZ.txt") Then
        ReadLogZ
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    WriteMyActivity("Activity_Pause " & UserClosed)
End Sub

Sub Btn1_Click
    StartActivity(prefScreen.CreateIntent)
End Sub

Sub WriteMyActivity(Msg As String)
    Dim Output As OutputStream = File.OpenOutput(File.DirDefaultExternal, "LogZ.txt", True)
      Dim tw As TextWriter
      tw.Initialize(Output)
    Dim Sample As String
    Sample=DateTime.Time(DateTime.Now) & " - " & Msg & CRLF
      tw.Write(Sample)
      tw.Close
End Sub

Sub CreatePrefs
    Dim PC As PreferenceCategory
    PC.Initialize("PC's title")
    PC.AddCheckBox("T1","Title1","Summary 1",False)
    PC.AddCheckBox("T2","Title2","Summary 2",False)
    prefScreen.AddPreferenceCategory(PC)
End Sub

Sub LogUpdatedKeys
    For Each K As String In prefManager.GetUpdatedKeys
        WriteMyActivity(K & ": " & prefManager.GetBoolean(K))
    Next
End Sub

Sub ReadLogZ
    Dim Input As InputStream = File.OpenInput(File.DirDefaultExternal,"LogZ.txt")
    Dim rw As TextReader
    rw.Initialize(Input)
    Dim sInput As String
    sInput=rw.ReadAll
    rw.Close
    LogColor("File's content: " & CRLF &sInput,Colors.Gray)
End Sub
 
Last edited:
Upvote 0

robotop

Member
Licensed User
Longtime User
Hi, about the flush, it will ensure (when used in output stream) that the buffered data will be sent immediatly to the output device (I use it when sending data on serial ports). Just for some additional info: what's the output of the LogZ.txt ? Are the preferences saved in any way ?
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
The output to LogZ.txt is null on the defective device and full of "Activity_Resume", etc on the others.
I will try with the flush command. Thanks a lot for your explanation.
About the preferences, yes, they are saved every time. That's the code inside the legacy subs which seems not to be executed which is very strange.
 
Upvote 0

robotop

Member
Licensed User
Longtime User
Yes, there must be something wrong. What Android version is implemented on the "defective" Moto G ? And: is your Android SDK up-to-date ? Are you using a compatible compiling model (adequate to the Moto G Android version) on SDK preferences ? Sorry for such amount of questions, but the behaviour you are experiencing is very unusual. May be the "guru" Erel will solve it in minutes, but not me ! :)
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
The emulator works well, only the real device does not. The Android's version is 4.4.3.
And I agree about the unbelievable aspect of the problem : remember that with a Log command and even a ToastMessageShow in the legacy subs they are not executed.
I am waiting for the Support's reply to my request by e-mail and will let you know. I guess Erel is working on this.
And if they are sceptics to this "magical" fact, I could record and post a video. I did not believe it myself. I can understand.
 
Last edited:
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
It is solved and it is my fault !

I have activated the System Shield from iolo's System Mechanics and I guess my fresh APK was not sent via USB to the device. With the Emulator or the devices connected using B4A-Bridge, I had no problem. With the MOTO G that, by habits, I connect via the USB, it executed the previous APK again and again.

I had not the idea to put a new object on the screen to check if it was refreshed before to spend your time with my stupid error. I am sorry for that. :oops:
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
It is solved and it is my fault !

I have activated the System Shield from iolo's System Mechanics and I guess my fresh APK was not sent via USB to the device. With the Emulator or the devices connected using B4A-Bridge, I had no problem. With the MOTO G that, by habits, I connect via the USB, it executed the previous APK again and again.

I had not the idea to put a new object on the screen to check if it was refreshed before to spend your time with my stupid error. I am sorry for that. :oops:
Boooooouuuuuuuuh ! :)
 
Upvote 0
Top