티스토리 뷰
Android/Kotlin
[Kotlin] Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
혀가 길지 않은 개발자 2020. 9. 2. 16:29Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1 페이지"
android:textSize="30dp" />
<Button
android:id="@+id/btnMain"
android:layout_width="220dp"
android:layout_height="80dp"
android:text="다음 페이지로 이동"
android:textSize="22dp"
android:layout_marginTop="100dp"/>
</LinearLayout>
activity_sub.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".SubActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2 페이지"
android:textSize="30dp" />
<Button
android:id="@+id/btnSub"
android:layout_width="220dp"
android:layout_height="80dp"
android:text="처음으로 이동"
android:textSize="22dp"
android:layout_marginTop="100dp"/>
</LinearLayout>
SubActivity.kt
package com.jwsoft.kotlinproject
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
btnMain.setOnClickListener {
val intent = Intent(this, SubActivity::class.java)
startActivity(intent)
}
}
}
MainActivity.kt
package com.jwsoft.kotlinproject
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
btnMain.setOnClickListener {
val intent = Intent(this, SubActivity::class.java)
startActivity(intent)
}
}
}
activity가 스택처럼 쌓인다.
SubActivity.kt
package com.jwsoft.kotlinproject
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_sub.*
class SubActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_sub)
btnSub.setOnClickListener {
val intent = Intent(this, MainActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(intent)
}
}
}
SubActivity.kt 에만
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK 추가
MainActivity.kt
package com.jwsoft.kotlinproject
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_sub.*
class SubActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_sub)
btnSub.setOnClickListener {
val intent = Intent(this, MainActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(intent)
}
}
}
MainActivity.kt 에도
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK 추가
'Android > Kotlin' 카테고리의 다른 글
[Kotlin] Tic-tac-toe 게임으로 보는 MVP 패턴 (0) | 2020.09.18 |
---|---|
[Kotlin] Tic-tac-toe 게임으로 보는 MVC 패턴 (0) | 2020.09.18 |
[Kotlin] lateinit vs Delegates.notNull<>() (0) | 2020.08.27 |
[Kotlin] InputMethodManager (0) | 2020.08.25 |
[Kotlin] STT (Speech-to-Text) (0) | 2020.08.24 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Architecture Pattern
- Kotlin
- MVVM
- Vue.js #Vue.js + javascript
- recyclerview
- JSONObject
- java
- 혀가 길지 않은 개발자
- fragment
- JSONArray
- Livedata
- 안드로이드
- handler
- 안드로이드 #코틀린 #Android #Kotlin
- CoordinatorLayout
- Android
- 코틀린
- DataBinding
- coroutine
- Design Pattern
- TabLayout
- 자바
- James Kim
- XML
- ViewModel
- View
- ViewPager2
- Intent
- ArrayList
- activity
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함