Android Question Bringing my app to the front

JakeBullet70

Well-Known Member
Licensed User
Hi all.

I have a service that is running and what I want to do is at a certain time bring my paused activity to the front. How do I do this?

Thanks.
 

udg

Expert
Licensed User
Hi Jack,

did you try
B4X:
StartActivity(Main)
from your service?
 

JakeBullet70

Well-Known Member
Licensed User
Yep, But it killed the previous instance. :(

'Killing previous instance (main).'
 

udg

Expert
Licensed User
Maybe
B4X:
If IsPaused("main") Then   StartActivity("main")
 

udg

Expert
Licensed User
What about a CallSubDelayed call from service to a specific Main's sub?
This way the existent activity should be awakened and after that the sub should execute.
 

JakeBullet70

Well-Known Member
Licensed User
Tried that. It does a:
'sending message to waiting queue (CallSubDelayed - AlarmStart)'
 

udg

Expert
Licensed User
I'm running out of ideas..eheh
Another approach could be that of setting a notification in the service, but this implies that the user could decide not to click on it.
 

JakeBullet70

Well-Known Member
Licensed User
OK... found this but have NO idea how to make this work. Not even sure if this is what I want but I think it is.

So what I am seeing here is.
Get an instance ActivityManager.
Get the task.id of my app.
make the call to moveTaskToFront

I am thinking maybe JavaObject or reflection? If one of you gurus could get me pointed in the right direction I would really appreciate it.

B4X:
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> tasklist =am.getRunningTasks(10); // Number of tasks you want to get

Then, you will have the active app list in  tasklist.  
moveTaskToFront () function will bring the app to foreground.
if(!tasks.isEmpty()) 
{
      int nSize = tasklist.size();
      for(int i = 0; i >= nSize;  i++) 
     {
            RunningTaskInfo taskinfo = tasklist.get(i);
           if(taskinfo.topActivity.getPackageName().equals("name of the package")) 
         {
                  am.moveTaskToFront(taskinfo.id, 0);
         }
     }
}
and then...
Finally, add permissions to the manifest.
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.REORDER_TASKS" />

Thanks all and thanks udg!
 

JakeBullet70

Well-Known Member
Licensed User
Here is what I am seeing.

This is the code that is making the call.
B4X:
Public Sub tmrTimersCheck
   
    Dim xx As Int
    Dim bIsActive As Boolean = False
    tmrTimers.Enabled = False
   
    For xx = 1 To 5
        If timers(xx).active = True Then
           
            If ProcessTimerCheck4Expire(xx) = True Then
                timers(xx).active = False
                bIsActive = g.iif(bIsActive,True,False)
                If IsPaused(Main) Then StartActivity(Main)
                CallSubDelayed2(Main,"AlarmStart",xx)
            Else
                bIsActive = True
            End If
           
        End If
    Next

    '--- if nothing is active so die earth timer!!!
    tmrTimers.Enabled = bIsActive
   
End Sub
And the error.

upload_2015-1-2_13-30-48.png



I have a LOG statement in the activity_resume but I am not seeing that.
Thanks!
 

udg

Expert
Licensed User
Hi Jake,

waiting for Erel indications, I noted a couple of points you may wan to investigate further.

Calling callsubdelayed is enough to wake up a module, so you don't need to precede it with startactivity.
the error in the log seems originated by sub updalistoftimersimg rather than activity's awakening.

Just my 2 cent
 

JakeBullet70

Well-Known Member
Licensed User
Yes, this is a Kiosk app on a tablet with 1gig of RAM. I have control over the other apps that can run.
On another note. Can an APP be marked as cannot be killed?

OK, after more testing. The code above works if I have switched to the calculator. It fails if I am looking at WiFi setup.... hhhhmmmm
 

thedesolatesoul

Expert
Licensed User

JakeBullet70

Well-Known Member
Licensed User
I think you are right. One thing though. activity_resume is called when the calculator app is active. But not when the wifi setup come back although activity isFirst is set to false in both cases.

Thanks. Time for more research. :)
 

JakeBullet70

Well-Known Member
Licensed User
On further review. This is working with every other program except the wifi setup when called by my program. If i go to the desktop and then go to wifi setup it works fine.

I use this to call the wifi setup.
B4X:
Public Sub WifiSettings  
    Dim DoAction As Intent
    DoAction.Initialize("android.settings.WIFI_SETTINGS","")
    StartActivity(DoAction)
End Sub
Anyway. Lets close this and move on. Thanks for every ones help!!!
 

JakeBullet70

Well-Known Member
Licensed User
Interesting, learning more everyday! OK, but if I was to call lets say skype from withing my program. Is it somehow attached to my process?
 
Top