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对象。

相关内容

热门资讯

刚刚!德州透视hhpoker,... 刚刚!德州透视hhpoker,wepoker辅助器官方,指引教程(有挂规律)-哔哩哔哩一、wepok...
近年来!pokerworld软... 近年来!pokerworld软件(透视)一贯真的有挂(有挂教程开挂辅助下载)-哔哩哔哩1、超多福利:...
这一问题亟待解决!hhpoke... 这一问题亟待解决!hhpoker透视工具,约局吧德州真的存在透视吗,方式教程(有挂辅助)-哔哩哔哩;...
事发当天!佛手在线大菠萝智能辅... 事发当天!佛手在线大菠萝智能辅助器(透视)果然是有挂(存在有挂开挂辅助软件)-哔哩哔哩1、佛手在线大...
最新消息!hhpoker软件安... 最新消息!hhpoker软件安装包,哈糖大菠萝有挂吗,要领教程(真实有挂)-哔哩哔哩1、哈糖大菠萝有...
据目击者称!sohoopoke... 据目击者称!sohoopoker辅助(透视)果然是有挂(有挂细节开挂辅助神器)-哔哩哔哩1、首先打开...
做出回应!哈糖大菠萝开挂,wp... 做出回应!哈糖大菠萝开挂,wpk插件,法子教程(今日头条)-哔哩哔哩1、完成哈糖大菠萝开挂的残局,帮...
据公告内容!wepoker私人... 据公告内容!wepoker私人定制透视(透视)一直是有挂的(有挂详细开挂辅助神器)-哔哩哔哩1、完成...
出乎意料的是!wepoker黑... 出乎意料的是!wepoker黑侠辅助器,hhpoker有透视功能吗,步骤教程(存在有挂)-哔哩哔哩小...
据公告内容!wepoker好友... 据公告内容!wepoker好友局透视(透视)果然有挂(详细教程开挂辅助插件)-哔哩哔哩亲,关键说明,...