添加LogActivity重载函数支持分屏模式切换
This commit is contained in:
@@ -103,6 +103,10 @@ public class MainActivity extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onLogTestNewTask(View view) {
|
||||||
|
LogActivity.startLogActivity(this, true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 日志测试按钮点击事件(打开日志查看界面)
|
* 日志测试按钮点击事件(打开日志查看界面)
|
||||||
* 启动 LogActivity,用于查看应用运行日志
|
* 启动 LogActivity,用于查看应用运行日志
|
||||||
|
|||||||
@@ -47,6 +47,18 @@
|
|||||||
android:onClick="onLogTest"
|
android:onClick="onLogTest"
|
||||||
android:layout_margin="10dp"/>
|
android:layout_margin="10dp"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="应用日志测试(新窗口)"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:background="#81C7F5"
|
||||||
|
android:paddingVertical="12dp"
|
||||||
|
android:layout_marginHorizontal="24dp"
|
||||||
|
android:onClick="onLogTestNewTask"
|
||||||
|
android:layout_margin="10dp"/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
android:resizeableActivity="true"
|
android:resizeableActivity="true"
|
||||||
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
|
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:launchMode="singleInstance"
|
android:launchMode="singleTop"
|
||||||
android:process=":LogActivity">
|
android:process=":LogActivity">
|
||||||
|
|
||||||
</activity>
|
</activity>
|
||||||
|
|||||||
@@ -46,19 +46,27 @@ public class LogActivity extends Activity {
|
|||||||
* @param context 上下文(Activity/Fragment),用于启动 Activity
|
* @param context 上下文(Activity/Fragment),用于启动 Activity
|
||||||
*/
|
*/
|
||||||
public static void startLogActivity(Context context) {
|
public static void startLogActivity(Context context) {
|
||||||
// 创建启动当前 Activity 的 Intent
|
startLogActivity(context, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动日志 Activity 的静态方法重载(外部调用入口)
|
||||||
|
* @param context 上下文(Activity/Fragment),用于启动 Activity
|
||||||
|
* @param newTask 是否在新窗口中启动
|
||||||
|
*/
|
||||||
|
public static void startLogActivity(Context context, boolean newTask) {
|
||||||
Intent intent = new Intent(context, LogActivity.class);
|
Intent intent = new Intent(context, LogActivity.class);
|
||||||
|
|
||||||
// 添加 Intent 标志:支持分屏/多窗口模式(API 24+)
|
if (newTask) {
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
|
intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
|
||||||
// 添加 Intent 标志:创建新任务栈(避免并入调用者任务栈)
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
||||||
// 添加 Intent 标志:标记为新文档(多任务窗口中独立显示)
|
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
} else {
|
||||||
// 添加 Intent 标志:允许创建多个任务实例(支持多次启动独立窗口)
|
intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
}
|
||||||
|
|
||||||
// 启动 Activity
|
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user