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

Fix leaking MainActivity #465

Merged
merged 1 commit into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ buildscript {
dokkaVersion = '1.4.10'
ktLintVersion = '0.39.0'
ktLintGradleVersion = '9.4.0'
leakcanaryVersion = '2.4'
leakcanaryVersion = '2.5'

// Testing
androidxTestCoreVersion = '1.3.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ internal object RepositoryProvider {
/**
* Idempotent method. Must be called before accessing the repositories.
*/
fun initialize(context: Context) {
fun initialize(applicationContext: Context) {
if (transactionRepository == null || throwableRepository == null) {
val db = ChuckerDatabase.create(context)
val db = ChuckerDatabase.create(applicationContext)
transactionRepository = HttpTransactionDatabaseRepository(db)
throwableRepository = RecordedThrowableDatabaseRepository(db)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ internal abstract class ChuckerDatabase : RoomDatabase() {
private const val OLD_DB_NAME = "chuck.db"
private const val DB_NAME = "chucker.db"

fun create(context: Context): ChuckerDatabase {
fun create(applicationContext: Context): ChuckerDatabase {
// We eventually delete the old DB if a previous version of Chuck/Chucker was used.
context.getDatabasePath(OLD_DB_NAME).delete()
applicationContext.getDatabasePath(OLD_DB_NAME).delete()

return Room.databaseBuilder(context, ChuckerDatabase::class.java, DB_NAME)
return Room.databaseBuilder(applicationContext, ChuckerDatabase::class.java, DB_NAME)
.fallbackToDestructiveMigration()
.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal abstract class BaseChuckerActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
RepositoryProvider.initialize(this)
RepositoryProvider.initialize(applicationContext)
}

override fun onResume() {
Expand Down