Android Question How To deal with notifications?

Discussion in 'Android Questions' started by FrankBerra, Aug 18, 2015.

  1. FrankBerra

    FrankBerra Active Member Licensed 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:
    Code:
    n.SetInfo("Test""New Message from " & user, SecondActivity)
    and this is the code of the SecondActivity:
    Code:
    Sub Activity_Create(FirstTime As Boolean)
         
    Activity.Color = Colors.ARGB (255111111111)
       
        
    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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    I've tried it in a simple app with two activities and it worked fine. The second activity is started when I click on the notification (when the first one is visible).
     
  3. FrankBerra

    FrankBerra Active Member Licensed 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?
     

    Attached Files:

  4. Erel

    Erel Administrator Staff Member Licensed User

    Note that you should use File - Export as zip when uploading project.
    What is the purpose of the CallSubDelayed call? It makes things more complicated.
     
  5. FrankBerra

    FrankBerra Active Member Licensed 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)?
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Yes. See Notification.SetInfo2.
     
    FrankBerra likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice