Skip to main content

Introduction and Example of Eventbus in Android.

EventBus is a library of Greenbot . This is very simple for all users how to implement and its basic use. Here I will also share examples for better understanding. What is EventBus? EventBus is subscribed/publish event bus to communication between components with limited lines of code, in short, its bus for events transfers the data between one activity(class) to another to reflect the changes based on our needs. That makes the data exchange between components like Activity, Fragment, Services, and any kind of backgrounds threads pretty easy. EventBus can handle the threading for us: events can be posted in threads different from the posting thread. Common use can be dealing with UI changes. In Android, UI changes must be done in the Main(UI) thread. In other words, networking or more time-consuming task cannot be handled in the Main thread, for that we must use AsyncTask or Handler to make it more smooth. Now we have one more options use EventBus to change the UI po

Disable Force Stop in Android


I have worked since 1 week on how to disable the FORCE STOP button in Manage Application in Android. And I was able to disable the Force Stop and Uninstall button in Manage Application.

For that you need to make your application as Device Administrator. Android has add this kind of feature from Android 2.2 version. This feature is for Security reason with different option. Set Minimum Password Strength, Data Wipe, Force Lock,  Reset Password and so on. We set our application as Device Administrator to change above features.

 For more info and advance example you can check your android-sdk path (>= android-8).  
 \samples\android-[>=8]\ApiDemos\src\com\example\android\apis\app\DeviceAdminSample.java 

See the below screen shots which shows how to activate the application and disable force stop button.

Disable Force Stop using Device Administrator - Prashant Adesara
[Active device adminstrator]



Disable Force Stop in Android - Prashant Adesara
[Disable the Force Stop and Uninstall button]



Follow the below steps to disable the FORCE STOP button.

1. Create one class with specific name and extends DeviceAdminReceiver.


2. Add main functionality under MainActivity to enable Device Admin Application.


3. Add below device_admin.xml file under /res/xml/ folder.


4. Add receiver in AndroidManifest.xml




You can also download full source from here. 
DeviceAdminDemo: https://github.com/prashantadesara/DeviceAdminDemo

Reference Site



If you are satisfied then please give your comments.
Thanks for your Interest!!!

Comments

  1. Hey Good tutorial..keep it up..
    But one question is, how to disable "Clear Cache" also, right now I can see "clear cache" Enable.

    ReplyDelete
    Replies
    1. Thanks for your interest.

      I thought "Clear Cache" is not able to disable due to its System level button. But If I find anyhow then share it here.

      Thanks,

      Delete
  2. Hi Prashant.

    I try to use your example in my Android, but this don´t disable the Force Stop button in settings.

    Only work the Uninstall button, when you try uninstaller. I had to add this line for uninstaller mDPM.removeActiveAdmin(mAdminName);

    Thanks for your answer.

    ReplyDelete
    Replies
    1. Hi Erick,

      Since Android 2.2, this new Device Policy API allowed to developer create this kind of feature.

      Which android device and version do you have?

      Delete
    2. Hi Prashant,

      I have the version 2.3.6 (Zombie art by Jack Larson) and the device is a Huawei Y200.

      Thanks for your answer.

      Delete
    3. Hi Erick,

      Then it must be work in your device because its android > 2.2 version.
      Can you please try to uninstall and install it again?

      You can check DeviceSample from below path in your Android-SDK path.
      \samples\android-[>=8]\ApiDemos\src\com\example\android\apis\app\DeviceAdminSample.java

      Thanks,

      Delete
    4. but its not working on android 7.1.1 and above

      Delete
  3. Nice tutorial.. thanks a lot for sharing it. :-)

    ReplyDelete
    Replies
    1. Hi,

      Thanks for your Interest and comments !!!

      Delete
  4. I do this example but nothing changed and i try to debug it on my galaxy note2 device and also nothing changed !!!!

    ReplyDelete
    Replies
    1. Hi

      I would suggest to can you please check again in same device ? May be something wrong from your side. Because I tested in Nexus 7 and its working perfectly even so many people visit this post and they got work perfectly.

      So just try again and let me know or else share some logs here. So I can identify what's problem in your side.

      Delete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Hi Prashant Adesara
    It's working fine but can you tell me how can i start this force stop button and uninstall it?

    ReplyDelete
    Replies
    1. Hi Pankaj,

      If you want to enable it again then go to Android device Settings -> Security -> Device Administrator -> and deselect the checkbox of your application.
      That's it.

      Thanks for your interest in my blog.

      Delete
  7. I add the code and nothing changed

    ReplyDelete
    Replies
    1. Hi Ahlam,

      Means you got any error? Please share here if you got any error.
      In which android device and version you try to run?

      Delete
  8. i am using your code on 2.3.6 but force stop button is still enable..can u plz guide me ??

    ReplyDelete
    Replies
    1. Hi Shubham,

      First install installed old version and than try to install the application. At the starting application ask for Device Manager policy. Just did it and then check your force stop button was disable automatically.

      Thanks,

      Delete
  9. Hi ,
    I used your code and tested on my Rooted Samsung Galaxy s3 and unrooted Nexus 4 but nothing happened.

    Can you kindly tell me how will it work ??

    ReplyDelete
    Replies
    1. Hi Noman,

      First installed old version and than try to install the fresh application again. At the starting application display dialog, Just click on Active button and then check your force stop button was disable automatically.

      Thanks,
      Prashant.

      Delete
  10. Hello Prashant:
    Nice code.

    Code runs ok in 4.4 but no in two Samsung with 2.3.6 (one GT P1000 and GT S6500). I tried "First installed old version and than try to install the fresh application again" but nothing. I have seen in several comments the same problem with 2.3.6... Buttons Force Close and Unistall are enabled although it is true uninstall finally no success. ¿A new advice to try?

    ReplyDelete
  11. This code works in a service? I have tried in a normal app and it works, but in a service not

    ReplyDelete
  12. very nice coding.... but i want disable only force stop button. how to modify? please tell me....

    ReplyDelete
  13. Hi Prashant Adesara,

    Thanks a lot for your help!
    It works perfectly and the tutorial is very clear.
    It was very helpful to me.
    I tested it on a device Samsung Galaxy Core GT-I8260L with Android version 4.1.2

    Thanks again!

    ReplyDelete
  14. Thank you prahant. It works perfect.

    ReplyDelete
  15. This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.
    Android Training in chennai | Best Android Training in chennai

    ReplyDelete
  16. Thanks for sharing this Informative content.
    Android Training in Noida

    ReplyDelete
  17. Thank you so much, only one thing left, can I install or uninstall applications silently and how?

    ReplyDelete
  18. Great post Concise and informative. Looking forward to more content like this. Keep up the good work.
    Active Rehabilitation Surrey

    ReplyDelete

Post a Comment

Popular posts from this blog

Android Client Connected with Socket Server

I hope this will help you for how to start communication between Socket Server (Desktop Chat Server Application) and Mobile Application (Android Socket Client). This application simply look like as chat application. You can add your idea and innovation to make very useful application. Follow below steps to run application: Use custom port and define same port in both application (i.e. Port No: 5657 ) Define computer IP Address in Android Client Application. (i.e. 192.168.1.x) . If you want to run this application in real device, then you can't connect with Desktop Socket Server. For that you need to upload runnable jar file in specific server and then you can use that server IP Address. First start Socket Server Application using Start button. Now you can start Android application. Just Enjoy it !!! Here I give you screen shot for communication between both application. [Socket Server (Desktop Application)] [Socket Client (Android Application)]

Introduction and Example of Eventbus in Android.

EventBus is a library of Greenbot . This is very simple for all users how to implement and its basic use. Here I will also share examples for better understanding. What is EventBus? EventBus is subscribed/publish event bus to communication between components with limited lines of code, in short, its bus for events transfers the data between one activity(class) to another to reflect the changes based on our needs. That makes the data exchange between components like Activity, Fragment, Services, and any kind of backgrounds threads pretty easy. EventBus can handle the threading for us: events can be posted in threads different from the posting thread. Common use can be dealing with UI changes. In Android, UI changes must be done in the Main(UI) thread. In other words, networking or more time-consuming task cannot be handled in the Main thread, for that we must use AsyncTask or Handler to make it more smooth. Now we have one more options use EventBus to change the UI po