提交 9bcf48d5 编写于 作者: 杜庆泉's avatar 杜庆泉

nativepage 新增关闭页面示例 https://ask.dcloud.net.cn/question/163268

上级 e8cfca63
...@@ -158,6 +158,23 @@ class StartThreadListener extends OnClickListener{ ...@@ -158,6 +158,23 @@ class StartThreadListener extends OnClickListener{
} }
} }
class ActivityFinishListener extends OnClickListener{
host:Activity
constructor(activity:Activity){
super()
this.host = activity
}
override onClick(v?: View):void{
Toast.makeText(UTSAndroid.getAppContext(),"手动关闭当前activity",Toast.LENGTH_LONG).show();
this.host.finish()
}
}
/** /**
* 自定义异步线程 * 自定义异步线程
*/ */
...@@ -232,6 +249,10 @@ class DemoActivity extends Activity{ ...@@ -232,6 +249,10 @@ class DemoActivity extends Activity{
let btn_start_thread = findViewById<Button>(R.id.btn_start_thread); let btn_start_thread = findViewById<Button>(R.id.btn_start_thread);
btn_start_thread.setOnClickListener(new StartThreadListener()); btn_start_thread.setOnClickListener(new StartThreadListener());
let btn_finish_activity = findViewById<Button>(R.id.btn_finish_activity);
btn_finish_activity.setOnClickListener(new ActivityFinishListener(this));
let recyclerView = findViewById<RecyclerView>(R.id.recycler_view) let recyclerView = findViewById<RecyclerView>(R.id.recycler_view)
let layoutManager = LinearLayoutManager(this); let layoutManager = LinearLayoutManager(this);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="开启前台服务(应用包活)" android:id="@+id/btn_start_service_front"/> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="开启前台服务(应用包活)" android:id="@+id/btn_start_service_front"/>
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="注册屏幕状态广播监听" android:id="@+id/btn_start_screen_listen"/> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="注册屏幕状态广播监听" android:id="@+id/btn_start_screen_listen"/>
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="开启异步任务" android:id="@+id/btn_start_thread"/> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="开启异步任务" android:id="@+id/btn_start_thread"/>
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="关闭当前activity" android:id="@+id/btn_finish_activity"/>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册