-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assistance Required for Clearing Application Data in MAUI App #26583
Comments
Is this in debug or release? I believe for debug we put some stuff in the cache for debugging purposes and if that is removed then the app won't launch indeed. |
@jfversluis We have tried running the app in release mode, but it crashes when executing the following line: val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager We are able to launch the app again, but it crashes when executing the above piece of code in release mode as well. Thank you in advance |
What does "crashing" mean? Do you have any log messages, error messages? Stack traces? Are you able to retrieve some data with logcat? |
@jfversluis I tried to capture the log but was unable to catch the exception using try-catch. The app crashed directly without logging anything. When calling the activityManager.clearApplicationUserData() method, the app crashes and no log is captured. |
Can you attach a logcat file with your crash? |
2024-12-17 15:38:43.086 1171-1424 HWComposer surfaceflinger E getSupportedContentTypes: getSupportedContentTypes failed for display 0: Unsupported (8) |
I have pasted the crash logcat file// @ |
@agni-svg I might not be seeing it but it looks like the log is getting cut off You might need to upload a file. |
@jfversluis @PureWeen please find the attached file for logcat. |
This issue has been moved from a ticket on Developer Community.
I am currently working on a MAUI application where we are attempting to clear the complete application data programmatically. Despite trying multiple solutions, we are unable to achieve the same results as manually clearing the app data. Actually this is an workaround for bigger problem which is getting fix after clearing the application data. The user impact is huge. Application deployed in Android Tablets OS version 13.
Despite these efforts, the application crashes after executing the code to clear app data, and it does not relaunch successfully. We need the data and cache clearing process to function similarly to the default settings menu options provided by the system.
We would greatly appreciate any advice or assistance you can provide in resolving this issue. Your expertise and support would be invaluable in helping us achieve the desired functionality.
Thank you in advance for your time and assistance.
Below are the code snippets we tried:
1). var packageName = context.PackageName;
var packageManager = context.PackageManager;
var applicationInfo = packageManager.GetApplicationInfo(packageName, 0);
packageManager.ClearApplicationUserData();
2). import android.app.ActivityManager
import android.content.Context
fun clearAppData(context: Context) {
val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
activityManager.clearApplicationUserData()
}
// Usage
val context = Android.App.Application.Context
clearAppData(context)
Also we tried to run below code for giving runtime permission and check whether we can able to clear app data or cache but getting result as a false.
<uses-permission android:name="android.permission.CLEAR_APP_DATA" />
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
public bool CanClearAppData()
{
// Check Android version
if ((int)Build.VERSION.SdkInt >= 30) // Android 11+
{
var packageManager = Android.App.Application.Context.PackageManager;
return packageManager.CanRequestPackageInstalls();
}
}
// Runtime Permission Request
private void RequestAppDataClearPermission()
{
if ((int)Build.VERSION.SdkInt >= 30)
{
var intent = new Intent(
Android.Provider.Settings.ActionManageAppAllFilesAccessPermission,
Android.Net.Uri.Parse("package:" + PackageName)
);
StartActivityForResult(intent, REQUEST_MANAGE_STORAGE);
}
}
Here our requirement is clear app data and cache should work as default option from setting menu.
Steps are mentioned below:
1).Open Settings: Go to the Settings app on your device.
2).Navigate to Apps: Find and tap on the "Apps" or "App Management" section.
3).Select the App: Scroll through the list of installed apps and select the one you want to clear data for.
4).Open Storage: Tap on "Storage" or "Storage & cache".
5).Clear Data: Tap on "Clear Data" or "Clear Storage" and confirm the action.
After executing above code, we are able to clear app data and cache but application is crashing and not able to launch the app again.
It should work same as system default clear cache and clear app data option.
Tried multiple solution but didn't work as expected.
Need support on issue.
Thanks in advance
Original Comments
Feedback Bot on 12/4/2024, 08:35 PM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Ramesh Kumar on 12/5/2024, 09:50 PM:
(private comment, text removed)
Vinay Kant Agnihotri on 12/6/2024, 03:24 AM:
AppCacheAndAppData.zip
"I have uploaded the sample file for your reference.
The app crashes while executing this piece of code: bool manager = activityManager.ClearApplicationUserData();
Despite the crash, the app launches successfully in release mode.
Is there any way to prevent app crashes?
Thank you in advance for your time and assistance.
Ramesh Kumar on 12/9/2024, 03:15 AM:
hello Microsoft team,
This ticket has been opened since a while now, could you please check and update whether there is any solution on how could clean complete app data programmatically, which has been similar to manual app data clear.
Appreciate your response.
The text was updated successfully, but these errors were encountered: