강의

멘토링

로드맵

인프런 커뮤니티 질문&답변

shafeel2님의 프로필 이미지
shafeel2

작성한 질문수

모던 안드로이드 - Jetpack Compose 입문

나만의 웹 브라우저 02 - ViewModel 작성

나만의 웹브라우져 02 코드실행시 에뮬레이터에 따라

작성

·

191

0

Galaxy Nexus API 34 일 경우는 정상적으로 실행되나

Pixel 7 Pro APi 34 일 경우는 실행중에 에뮬레이터가 사라집니다

 

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            HomeScreen()
        }
    }
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun HomeScreen() {
    Scaffold (
        topBar = {
            TopAppBar(
                title = { Text("")},
                actions = {
                    IconButton(onClick = {

                    }){
                        Icon(
                            imageVector = Icons.Default.ArrowBack,
                            contentDescription = "back",
                            tint = Color.White
                        )
                    }
                    IconButton(onClick = {

                    }){
                        Icon(
                            imageVector = Icons.Default.ArrowForward,
                            contentDescription = "forward",
                            tint = Color.White
                        )
                    }
                }
            )
        }
    ) { paddingValues ->
        Column(
            modifier = Modifier
                .padding(16.dp)
                .fillMaxSize()
        ) {
            OutlinedTextField(
                value = "",
                onValueChange = {},
                label = { Text("https://")},
                modifier = Modifier
                    .padding(paddingValues)
                    .fillMaxWidth(),
                keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),
                keyboardActions = KeyboardActions(onSearch = {}),
            )
            Spacer(modifier = Modifier.height(16.dp))
            MyWebView()
        }
    }
}

@Composable
fun MyWebView() {
    AndroidView(
        modifier = Modifier.fillMaxSize(),
        factory = {
            WebView(it).apply {
                settings.javaScriptEnabled = true
                webViewClient = WebViewClient()
                loadUrl("https://google.com")
            }
        },
        update = {},
    )
}

답변 1

0

오준석님의 프로필 이미지
오준석
지식공유자

에뮬레이터가 강제종료 된 것으로 보이는데, 일단 코드의 문제는 아니기 때문에 잘 되는 에뮬에서 진행해 주시면 될 것 같습니다.

shafeel2님의 프로필 이미지
shafeel2

작성한 질문수

질문하기