@@ -12,7 +12,7 @@ import com.google.firebase.storage.UploadTask
12
12
abstract class UploadActivity : AppCompatActivity () {
13
13
14
14
// storageRef was previously used to transfer data.
15
- private var storageRef: StorageReference ? = null
15
+ private lateinit var storageRef: StorageReference
16
16
private var saved: Boolean = false
17
17
18
18
override fun onCreate (savedInstanceState : Bundle ? ) {
@@ -40,16 +40,16 @@ abstract class UploadActivity : AppCompatActivity() {
40
40
41
41
// Find all UploadTasks under this StorageReference (in this example, there should be one)
42
42
43
- storageRef?.activeUploadTasks?.let { it ->
44
- if (it.size > 0 ) {
45
- // Get the task monitoring the upload
46
- val task = it[0 ]
43
+ val tasks = storageRef.activeUploadTasks
47
44
48
- // Add new listeners to the task using an Activity scope
49
- task.addOnSuccessListener(this ) {
50
- // Success!
51
- // ...
52
- }
45
+ if (tasks.size > 0 ) {
46
+ // Get the task monitoring the upload
47
+ val task = tasks[0 ]
48
+
49
+ // Add new listeners to the task using an Activity scope
50
+ task.addOnSuccessListener(this ) {
51
+ // Success!
52
+ // ...
53
53
}
54
54
}
55
55
}
@@ -61,7 +61,7 @@ abstract class UploadActivity : AppCompatActivity() {
61
61
var uploadTask: UploadTask
62
62
63
63
// [START save_before_restart]
64
- uploadTask = storageRef!! .putFile(localFile)
64
+ uploadTask = storageRef.putFile(localFile)
65
65
uploadTask.addOnProgressListener { taskSnapshot ->
66
66
sessionUri = taskSnapshot.uploadSessionUri
67
67
if (sessionUri != null && ! saved) {
@@ -75,7 +75,7 @@ abstract class UploadActivity : AppCompatActivity() {
75
75
// [START restore_after_restart]
76
76
// resume the upload task from where it left off when the process died.
77
77
// to do this, pass the sessionUri as the last parameter
78
- uploadTask = storageRef!! .putFile(localFile,
78
+ uploadTask = storageRef.putFile(localFile,
79
79
StorageMetadata .Builder ().build(), sessionUri)
80
80
// [END restore_after_restart]
81
81
}
0 commit comments