Android Question StartActivity from Service and Lock Screen

Luiz Fernando Orlandini

Active Member
Licensed User
Longtime User
Hi All,

I'm getting a not desired behavior in my APP.

I receive a new message form GCM, and I need to launch an Activity to user send some action (reject ou accept the order).

Everything works fine if I don't have the device protected my some kind of password.

When I receive the message, I launch the activity.

The code bellow runs under a GCM Service

B4X:
Dim In As Intent
In.Initialize(In.ACTION_MAIN,"")
In.SetComponent("mypackage/.main")
In.Flags = 33554432 'FLAG_ACTIVITY_FORWARD_RESULT
StartActivity(In)
CallSubDelayed2(Main, "NewNotificationArrived", Intent)

Anybody can help to modify this, that even with the application with the screen turned off and protected by password could launch my activity?

This is the same behavior we got in a typical Alarm APP.

Thanks.
 

Luiz Fernando Orlandini

Active Member
Licensed User
Longtime User
Really not luck at all!

When I just turned off the screen but with my app online, these intent doens't launch the activity like I desire. When I turn on the screen, the message is processed.

Anybody could have any ideia?
 
Upvote 0

Luiz Fernando Orlandini

Active Member
Licensed User
Longtime User
Hi Erel.

The Notification is running in a service. These behavior occurs only when the APP is not minimized (by home button) and the screen is turned off.

Thanks.
 
Upvote 0

Luiz Fernando Orlandini

Active Member
Licensed User
Longtime User
Erel, I'm using PhoneWakeState.

But I'm afraid this is not the point.

Imagine the user is using the APP, and decide to turn off the screen light without minimize the application. This is possible, right?

At this time, when a new notification arrived, nothing happens, until the screen is turned on. Looks like, the application has freezed and will wake up just after the screen turned on again.

Maybe, some new combination of flags it's necessary to do that, but I need some help with that.
 
Upvote 0

Luiz Fernando Orlandini

Active Member
Licensed User
Longtime User
Erel,

this is done, but the behavior continues the same.

B4X:
Sub Activity_Resume
    If(GPSTrack.GPSPhone.IsInitialized) Then
        If GPSTrack.GPSPhone.GPSEnabled = False Then
            ToastMessageShow("Por favor, habilitar o GPS de seu telefone", True)
            StartActivity(GPSTrack.GPSPhone.LocationSettingsIntent) 'Will open the relevant settings screen.
        End If
    End If

    SetShowWhenLocked
   
    WakeState.KeepAlive(False)
End Sub


Sub Activity_Pause (UserClosed As Boolean)
    Log("Activity_Pause")
    If UserClosed Then
        Log("Aplicação encerrada")
        StateManager.ResetState("Main")
        ExitApp(UserAvailable)
    Else
        StateManager.SaveState(Activity, "Main")
    End If
   
    StateManager.SaveSettings
    WakeState.ReleaseKeepAlive   
End Sub
 
Upvote 0

Luiz Fernando Orlandini

Active Member
Licensed User
Longtime User
Sorry my delay Erel.

Here is the code...

B4X:
Dim In As Intent
In.Initialize(In.ACTION_MAIN,"")
In.SetComponent("mypackage/.main")
In.Flags = 33554432 'FLAG_ACTIVITY_FORWARD_RESULT
StartActivity(In)
CallSubDelayed2(Main, "NewNotificationArrived", Intent)
 
Upvote 0

Luiz Fernando Orlandini

Active Member
Licensed User
Longtime User
Erel, it's the same APP.

Just one correction...

B4X:
        Dim In As Intent
        In.Initialize(In.ACTION_MAIN,"")
        In.SetComponent("mypackage/.main")
        In.flags = 6815872 'FLAG_TURN_SCREEN_ON, FLAG_DISMISS_KEYGUARD, FLAG_SHOW_WHEN_LOCKED and FLAG_KEEP_SCREEN_ON
        'In.Flags = 33554432 'FLAG_ACTIVITY_FORWARD_RESULT
        StartActivity(In)

The code below is the code that is running im my app.

In the first momento, I used to call StartActivity(Main), but this results in a not desired behavior: when the GCM notification arrived, the APP does'nt start until you turn of the screen, if the screen is off.

In my research at forum I found this piece of code, that uses to simulate the same behavior of alarm clock Apps, that is similar my necessity.

The interesting is that if the application is up and the user turn off the screen, when a new notification arrives, the Activity is not launch.

Is it clear? Can you have any different suggention?
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…