0

I want to develop an app which needs to be in memory until user clicks the force stop button in the task manager screen then only its broadcast receivers can trigger by particular event and i can do my works.

I have been searching for this solution a long time. A lot saying that's not possible. But i have seen that face book and class of clans applications always running and kept in memory even clearing all recent applications. Now someone help me how to do that? Thanks in advance!

Update: I used Services Which returns START_STICKY its not a good idea when lower memory devices.. and I used

 startForeground(id, notification);

still some devices clears the foreground service if i clear recent items...

watsapp and Facebook like applications using some ideas to do that without foreground notifications...In all of the devices clearing recent items doesnt affect the applications services like facebook and watsapp those applications services always running and I am keep receiving notifications from them!!

All I need is I want my receiver to run until I uninstall my app or go-to task manager and force closes it or android closes it under some low memory circumstances... Until that imy receiver has to go on .. that's it!

Hope you guys understand my pblm!!!

Mr.Popular
  • 845
  • 1
  • 8
  • 15
  • please read before down voting man... can you give me the answer??? – Mr.Popular Dec 19 '16 at 07:40
  • 1
    Welcome to StackOverflow. Please note, that this is not a free code-writing service, but we are eager to help fellow programmers (and aspirants) writing their own code. Please read the help topics on [How to ask a good question](http://stackoverflow.com/help/how-to-ask). Afterwards, please update your question with the code you have written thus far in order to complete the task(s) you wish to achieve. – Quintin Balsdon Dec 19 '16 at 08:24
  • maibe you need a foreground service? – Vladyslav Matviienko Dec 19 '16 at 08:53
  • The answer is [here](https://developer.android.com/guide/components/services.html). You need read the tutorial and try yourself. When you get stuck and have a specific question, we will be happy to answer questions. – David Rawson Dec 19 '16 at 09:28
  • guys all services will get destroyed if i clear recent apps guys.. i already posted a question but no one responded – Mr.Popular Dec 19 '16 at 10:46
  • i am using android 4.4 device.. even i used foreground service to run my project it also destroyed in lenova a6000+ android 5.0 this also clear my services and all – Mr.Popular Dec 19 '16 at 10:48
  • @QuintinBalsdon i was asking the idea.. i didn't want you to write coding for that.. – Mr.Popular Dec 19 '16 at 10:50
  • @VladMatvienko lenova a6000+ clears the foreground service – Mr.Popular Dec 19 '16 at 10:51
  • @DavidRawson do i need to use any service to keep my receiver working??? I used static declaration of receiver by putting receiver in the manifest file – Mr.Popular Dec 19 '16 at 10:57
  • @Mr.Popular your service needs to return START_STICKY in the onStart() method. Then if it gets destroyed, Android will restart it for you. – David Rawson Dec 19 '16 at 17:29
  • The reason your questions are getting downvoted and not answered is because you are not asking correctly. There is a 'how to ask' section in 'help'. If you are having a problem with a specific service you need to post a minimum, complete, and verifiable example. If we don't see any code then how can we help? – David Rawson Dec 19 '16 at 17:41
  • START_STICKY is the correct solution. If it's "not a good idea on low memory devices" then neither is running Facebook and Class [sic] of the Clans since their solution probably uses that. – David Rawson Dec 19 '16 at 17:47
  • @DavidRawson STart_STICKY not working.. I have tried this before.. whenever I clear ma recent apps my app destroyed I am saying this by checking task manager force stop button disabled.. but WhatsApp and coc apps are not ... I was asking ABT that idea.. – Mr.Popular Dec 19 '16 at 17:56
  • http://stackoverflow.com/a/17246046/5241933 – David Rawson Dec 19 '16 at 18:03
  • @DavidRawson I don't want to disable my apps force stop button.. I just want my receiver to keep running that's all... If may app is running means my receiver working perfectly.. but if I clear my recent apps it completely destroyes my application my receiver everything.. so how can we achieve it?? Android os destroys completely an app if there is no usages.. so I thot if there is way to make my app prevent like still it has some works to do... Am not sure about that... So only am asking you to help me – Mr.Popular Dec 19 '16 at 20:19
  • It's not clear what you want - it seems like you keep changing it. Or at least you can't express it as a clear requirement. I suggest you look at the [source code for Telegram Android](https://github.com/DrKLO/Telegram). It has a background service that is like Facebook and stays in the background. – David Rawson Dec 19 '16 at 20:45
  • @DavidRawson I didn't change anything.. I just want u to understand my question... That's y I am keep explaining wat my pblm is... – Mr.Popular Dec 20 '16 at 04:54
  • @DavidRawson can u create one app which app's receiver has to meet my scenario??? Can you do it?? If yes tell me the way how to make that possible??? Without foreground notifications like Facebook WhatsApp and coc apps – Mr.Popular Dec 20 '16 at 04:58
  • Still not 100% sure what you want but take a look at [this answer](http://stackoverflow.com/a/26026471/5241933). You would create a broadcast receiver to listen for boot. Then in the receiver, start your service. Make sure it returns `START_STICKY` from `onStart();` (don't return `super.onStart()`). – David Rawson Dec 20 '16 at 05:53
  • @DavidRawson should i use a service to keep my receiver working???? – Mr.Popular Dec 20 '16 at 06:41
  • @DavidRawson documents says that if i give receiver declaration in manifest it ll work just fyn.. but if i clear recent apps it stopped working – Mr.Popular Dec 20 '16 at 06:42
  • Plz check in your mobile configuration turn off battery save or Optimize battery for your app.. it might work – Parth Dec 20 '16 at 12:46
  • @Parth if it is then how can watsapp and other apps can do it??? am i wrong?? – Mr.Popular Dec 20 '16 at 12:47
  • i am not sure but for that GCM sending High priority msg. that will wake up your app . – Parth Dec 20 '16 at 12:51
  • @Parth is there anyway can i do it to my app??? – Mr.Popular Dec 20 '16 at 12:55

0 Answers0