Android Question How To deal with notifications?

FrankBerra

Active Member
Licensed User
Longtime User
Hi all!

I have two activities: Main and SecondActivity
I have also a service listening for push messages and display notifications: this is the code that opens the SecondActivity if i click on the notification:
B4X:
n.SetInfo("Test", "New Message from " & user, SecondActivity)

and this is the code of the SecondActivity:
B4X:
Sub Activity_Create(FirstTime As Boolean)
     Activity.Color = Colors.ARGB (255, 111, 111, 111)
   
    ToastMessageShow("OK", False)
    CallSubDelayed(Main, "OpenFromNotification_Click")

End Sub

Sub Activity_Resume
 
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Activity.Finish
End Sub

Everything works fine if the app is closed. I click on the notification and Voilà it starts OpenFromNotification_Click sub in Main activity.

Tre problem occours when the Main activity is opened: if I click on the notification when the main activity is opened nothing happens.
Seems like the SecondActivity is not launched, infact the ToastMessageshow doesn't pops up.

My question is: how i start "OpenFromNotification_Click" subroutine from notification even the main activity is open?

Thanks in advance
 

FrankBerra

Active Member
Licensed User
Longtime User
Well, i created a test app and the problem persists!
Please take a look to the attached project and follow these steps to reproduce the problem:

1. Start Service (with the first button)
2. Close the app with back key
3. Wait for notification
4. Click on the notification and the app starts displaying a messagebox. GOOD! Close the messagebox.
5. Click on "Button" to fire a new notification
6. Now clicking on the notification the messagebox doesn't appear again!

Where i am wrong?
 

Attachments

  • TestActivity.zip
    371.9 KB · Views: 158
Upvote 0

FrankBerra

Active Member
Licensed User
Longtime User
With CallSubDelayed i call a specific subroutine of main activity that handle the routines that i want to execute after user clicks on the notification.
I want also to call that soubroutine directly by pressing the "Button" in main activity.

So, are there some easy ways to do that? For example is it possible to know if i open the app from a notification (without using SecondActivity)?
 
Upvote 0
Top