i need to clear cache of an app without force closing the app. i need app to continue running. i am using espresso to test application but i need to clear cache before the app starts. is there any possible way to do it ?
public static void clearPreferences(Activity activity) {
try {
// clearing app data
String packageName = activity.getPackageName();
Runtime runtime = Runtime.getRuntime();
runtime.exec("pm clear "+packageName);
} catch (Exception e) {
e.printStackTrace();
}
}
this is what i have. but it closes the app and terminates test case