티스토리 뷰

728x90



새로운 task 생성하기

◼ Manifest

 android:launchMode = ["standard" | "singleTop" | "singleTask" | "singleInstance"]

 

◼ Intent flag

 FLAG_ACTIVITY_SINGLE_TOP
 FLAG_ACTIVITY_NEW_TASK
 FLAG_ACTIVITY_MULTIPLE_TASK



FLAG_ACTIVITY_SINGLE_TOP

대상 task 는 하나의 instance 만 사용한다.

활성화 될 task 의 top 에 같은 activity 가 존재할 경우, 새로운 activity 를 top 으로 올리지 않고 기존의 top 을 재사용.

(launchMode="singleTop" 과 FLAG_ACTIVITY_SINGLE_TOP 은 동일한 기능이다)

 

A1 activity 가 A2 activity 를 활성화 하고 A2 는 다시 자신을 활성화 하는 예를 들면 아래와 같다.

 

◼ FLAG_ACTIVITY_SINGLE_TOP 이 아닌 경우

 

 

◼ FLAG_ACTIVITY_SINGLE_TOP



Code

A2 activity

Intent intent = new Intent(getApplication(), A2.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
view raw a2.java hosted with ❤ by GitHub

 

Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.parkho.tasksample">
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".A1">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".A2" />
</application>
</manifest>



ADB

adb shell dumpsys activity

ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)
Display #0 (activities from top to bottom):
Stack #1:
Task id #136
TaskRecord
Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.parkho.tasksample/.A1 }
Hist #1: ActivityRecord
Intent { cmp=com.parkho.tasksample/.A2 }
ProcessRecord
Hist #0: ActivityRecord
Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.parkho.tasksample/.A1 }
ProcessRecord
view raw logcat hosted with ❤ by GitHub



728x90
댓글