java - Clearing application data programatically android -


I have an app with SharedPreferences. I clicked on a button to clear the complete apps data so that the application started as a fresh reason when it was first installed.

I have tried: -

< P> ClearData.java

expanded public class ClearData application {Private Static ClearData example; @ Override Public Empty on Create () {Super. Connet (); Example = this; } Public Fixed ClearData getInstance () {return example; } Public Zero Clear Display Data () {file cache = would match (); File apiar = new file (cache.getpartent ()); If (appDir.exists ()) {string [] children = appDir.list (); For (strings: children) {if (! S.equals ("lib")) {deleteDir (new file (appDir, s)); Log.i ( "tag", "**************** delete the file / data / data / Mypackage /" + s + "given ******** *** ******** "); }}}} Public static Boolean deleteDir (file dir) {if (dir = Null & amp; amp;; dir.isDirectory ()) {String [] children = dir.list (); For (; i & lt; i = 0 int children.length; i ++) {boolean success = deleteDir (new File (dir, children [i])); If (! Success) {return false; }}} Return dir.delete (); }}

Main.Java

  btnLogout.setOnclickListener (see the new OnClickListner ({@Override Public Zero (click V) {ClearData. GetInstance). Please do not include the unchanged data (); // gatin error}}  

but I get a NullPointerException on the top line

  Clear application data (context macintex)  

enter post "itemprop =" text ">

 < code> instead of  

and

  file cache = mContext.getCacheDir ();  instead of 

instead of

  file cache = getCacheDir () ;.  

The main activity in itself phone

  clear Aplikeshndeta (getBaseContext ());  

Click the button btnLogout. Hope it helps.


Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -