Skip to content
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

Use system service for app reset #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package eu.pretix.pretixscan.droid.ui


import android.app.AlarmManager
import android.app.Fragment
import android.app.FragmentTransaction
import android.app.PendingIntent
import android.app.*
import android.content.Context
import android.content.Context.ACTIVITY_SERVICE
import android.content.Intent
import android.net.Uri
import android.os.Build
Expand Down Expand Up @@ -91,18 +89,20 @@ class SettingsFragment : PreferenceFragment() {
findPreference("full_delete")?.setOnPreferenceClickListener {
alert(Material3, R.string.full_delete_confirm) {
yesButton {
val conf = AppConfig(activity)
conf.resetDeviceConfig()

activity.deleteDatabase(Models.DEFAULT.name)

val mStartActivity = Intent(activity, WelcomeActivity::class.java)
val mPendingIntentId = 123456
val mPendingIntent = PendingIntent.getActivity(activity, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT)
val mgr = activity.getSystemService(Context.ALARM_SERVICE) as AlarmManager
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent)
System.exit(0)

if (Build.VERSION.SDK_INT >= 19) {
val am = activity?.getSystemService(ACTIVITY_SERVICE) as ActivityManager
am.clearApplicationUserData()
} else {
activity.deleteDatabase(Models.DEFAULT.name)
val conf = AppConfig(activity)
conf.resetDeviceConfig()
val mStartActivity = Intent(activity, WelcomeActivity::class.java)
val mPendingIntentId = 123456
val mPendingIntent = PendingIntent.getActivity(activity, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT)
val mgr = activity.getSystemService(Context.ALARM_SERVICE) as AlarmManager
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent)
System.exit(0)
}
}
noButton { }
}.show()
Expand Down