Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
IBMS
/
nativeview
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e7cc5313
authored
Feb 23, 2022
by
huangzhicong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复可能在lifecycleScope未执行完抛出的异常导致崩溃的问题
parent
51cb0ccd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
11 deletions
+18
-11
app/src/main/java/com/maxrocky/nativeview/fragment/StartFragment.kt
+18
-11
No files found.
app/src/main/java/com/maxrocky/nativeview/fragment/StartFragment.kt
View file @
e7cc5313
...
@@ -17,6 +17,7 @@ import kotlinx.coroutines.Dispatchers
...
@@ -17,6 +17,7 @@ import kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.flow.collect
import
kotlinx.coroutines.flow.collect
import
kotlinx.coroutines.flow.map
import
kotlinx.coroutines.flow.map
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.withContext
class
StartFragment
:
Fragment
()
{
class
StartFragment
:
Fragment
()
{
companion
object
{
companion
object
{
...
@@ -46,18 +47,25 @@ class StartFragment : Fragment() {
...
@@ -46,18 +47,25 @@ class StartFragment : Fragment() {
button
.
setOnClickListener
{
button
.
setOnClickListener
{
val
url
=
urlEditText
.
text
.
trim
().
toString
()
val
url
=
urlEditText
.
text
.
trim
().
toString
()
if
(
url
.
isNotEmpty
())
{
if
(
url
.
isEmpty
())
{
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
findNavController
().
navigate
(
val
storageKey
=
stringPreferencesKey
(
STORAGE_URL
)
R
.
id
.
action_startFragment_to_mainFragment
,
context
?.
dataStore
?.
edit
{
MainFragment
.
createStartBundle
(
url
)
it
[
storageKey
]
=
url
)
}
return
@setOnClickListener
}
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
val
storageKey
=
stringPreferencesKey
(
STORAGE_URL
)
context
?.
dataStore
?.
edit
{
it
[
storageKey
]
=
url
}
withContext
(
Dispatchers
.
Main
)
{
findNavController
().
navigate
(
R
.
id
.
action_startFragment_to_mainFragment
,
MainFragment
.
createStartBundle
(
url
)
)
}
}
}
}
findNavController
().
navigate
(
R
.
id
.
action_startFragment_to_mainFragment
,
MainFragment
.
createStartBundle
(
url
)
)
}
}
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment