3

After I made some researches, I found out there is only one way to restart an app and bring it to foreground from background. They say I should use services to do that. But all of the answers refer to developer.android. And I'm not yet able to use developer.android. Don't ask why.

What I want?
When user goes out of my app (go to another app, menu, or going to settings) somehow, listen it with BroadcastReceiver or services. Then bring my app back to foreground.

What I did so far?
I've tried some code snippets but they didn't give me the solution. I guess I didn't understand the basic of services and broadcastreceiver. This is the only point that I stuck with.

I'm sure it will be a few lines of codes. I'm waiting help from you guys.

Charles
  • 50,943
  • 13
  • 104
  • 142
zbgokalp
  • 163
  • 1
  • 2
  • 11
  • 1
    Please edit your question to replace all occurrences of the pronoun "it" with the nouns that you are attempting to refer to. – CommonsWare May 31 '12 at 19:19
  • in other words you wana make your app always on top? or you wana make your own launcher/homeapp? – Selvin May 31 '12 at 19:36
  • It's basicly a launcher that only allows authorized people to go to settings etc. But for example, an UNauthorized user can go to settings with the System Bar at the bottom (which is something I don't want) and when UNauthorized user did that I want to turn back to my app. So I won't let any UNauthorized user to change settings or do anything else. – zbgokalp May 31 '12 at 19:39
  • Thanks Selvin but I know it's possible. I even used some apps doing that. But they were too complicated. I know it's something that only major Android Developers know but it is definitely possible. – zbgokalp May 31 '12 at 19:49
  • "I even used some apps doing that" -- name any. – CommonsWare May 31 '12 at 19:51
  • Surelock for example. It listens (somehow) when you go to settings or somewhere else, then it turns back to main (launcher) app. It won't let you to do any changes. – zbgokalp May 31 '12 at 19:54
  • 1
    @zbgokalp: Sure Lock seems to be actually replacing the main launcher with their own (locking it in as default; then you can't go back to the main launcher without a password). – Kevin Coppock May 31 '12 at 20:06
  • Thanks kcoppock. And yes surelock does that. But it's biggest feature is not replacing itself as launcher but to listening all unwanted attempts (such as going to settings, trying to change wifi status etc) and not allowing UNautorized users to do that. That's where I'm interesting in. Making launcher is very easy but what I want is to listen when user go to settings or go to somewhere elser than my launcher and then bring my app back to foreground. – zbgokalp May 31 '12 at 20:09
  • If what you say is true, then I'll spend some time figuring out how they are doing this, then I will take steps to ensure the security flaw they are exploiting gets fixed. Thank you for your efforts at exposing security flaws that malware authors could use to lock people out of their devices. – CommonsWare May 31 '12 at 20:43
  • 2
    I guess that's why I never got correct answers to my questions. But ofcourse a book author don't know about those features. They only knew and write basics. Sorry for those readers. And sorry cause I forgot to add "this is only for major coders" at my question's header. You may go to do some figuring out and reporting, noone will care anyway. In the end major coders don't see it as security flaw. – zbgokalp May 31 '12 at 21:15

1 Answers1

2

It is definitely possible (Surelock does it). But i guess u cannot do it using BroadcastReceiver as there is no broadcast sent by the system when an application is launched.

You can bring your activity to the foreground by starting an intent of your activity from your service. But your challenge is to determine when you should start your activity.

If you want to run a single activity "always on top" then you can use this technique. It doesn't even require Service implementation.

Hope this solves some of your issues.

Community
  • 1
  • 1
PC.
  • 6,870
  • 5
  • 36
  • 71
  • Thanks for the answer. That was the right answer and I voted it and checked it. but I'm using a different method now to prevent the user going anywhere elser than my app. Also it is really good to hear from someone who really knows coding and workarounds :) – zbgokalp Jun 23 '12 at 22:33