AndroidPresentation在没有视图上下文的情况下引起StrictModeViolation,尽管已经具有活动上下文。
创始人
2024-10-09 14:34:53
0

使用具有视图上下文的构造函数创建Presentation对象。

例如,在MainActivity中创建Presentation对象:

public class MainActivity extends AppCompatActivity {
    private MyPresentation myPresentation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Instantiate and show the presentation
        if (myPresentation == null) {
            myPresentation = new MyPresentation(this, getWindow().getDecorView());
            myPresentation.show();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // Dismiss the presentation when the activity is destroyed
        if (myPresentation != null) {
            myPresentation.dismiss();
            myPresentation = null;
        }
    }

    private static class MyPresentation extends Presentation {
        public MyPresentation(Context context, Display display) {
            super(context, display);
        }

        // Other methods for Presentation
    }
}

这里的MyPresentation类扩展Presentation类,并在其构造函数中使用Context和Display对象作为参数。这样可以避免任何StrictMode违规错误。在MainActivity中,我们将获取活动上下文和视图层次结构的根视图并传递给MyPresentation构造函数。然后,我们调用MyPresentation的show()方法来显示它。在MainActivity的onDestroy()方法中,我们释放MyPresentation对象。

相关内容

热门资讯

黑科技安装(wepoke透明黑... 【福星临门,好运相随】;黑科技安装(wepoke透明黑科技)wepoke计算辅助(WepoKe)从来...
黑科技辅助(wepokeai代... 自定义系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅助器,不管你是想分享给你好...
黑科技辅助挂(wepoke智能... 黑科技辅助挂(wepoke智能ai)Wepoke辅助从哪里下载(wepOke)竟然是真的有挂(了解有...
黑科技ai(wepoke真的有... 黑科技ai(wepoke真的有挂)wepoke辅助挂在哪开(WePoKer)从前存在有挂(有人有挂)...
黑科技私人局(wepoke真的... 黑科技私人局(wepoke真的有挂)wepoke是不是有挂(wepokE)切实真的有挂(有挂方针)-...
黑科技辅助挂(wepoke真的... 黑科技辅助挂(wepoke真的有挂)wepower有外挂(wEpOke)竟然存在有挂(有挂存在)-哔...
黑科技ai(wepoke黑科技... 黑科技ai(wepoke黑科技)德州poker有外挂吗(wEpOke)真是是有挂(有挂透明挂)-哔哩...
黑科技脚本!来玩德州app服务... 黑科技脚本!来玩德州app服务器在哪里(wepoke智能ai)一向有挂(有挂细节)-哔哩哔哩1、用户...
黑科技线上!aapoker挂(... 黑科技线上!aapoker挂(德州ai辅助神器软件)总是是真的有挂(有挂讲解)-哔哩哔哩1、完成德州...
黑科技挂!wepoke辅助技巧... 黑科技挂!wepoke辅助技巧(wepoke有没有挂)一向真的是有挂(有挂猫腻)-哔哩哔哩;一、we...