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

相关内容

热门资讯

辅助黑科技(WPK机器人)外挂... 辅助黑科技(WPK机器人)外挂透明挂辅助黑科技(透明挂)切实有挂(有挂教程)-哔哩哔哩1、任何WPK...
黑科技好友房(wepoke线上... 黑科技好友房(wepoke线上)外挂透明挂辅助代打(软件透明挂)一贯真的是有挂(有挂技术)-哔哩哔哩...
黑科技软件(菠萝德州app)外... 黑科技软件(菠萝德州app)外挂透明挂辅助软件(黑科技ai)竟然真的有挂(有挂教程)-哔哩哔哩进入游...
黑科技脚本(WPK)外挂透明挂... 黑科技脚本(WPK)外挂透明挂辅助挂(黑科技ai)真是真的有挂(有人有挂)-哔哩哔哩1.WPK ai...
黑科技辅助(Wepoke辅助挂... 黑科技辅助(Wepoke辅助挂)外挂透明挂辅助黑科技(黑科技ai)其实是有挂(真实有挂)-哔哩哔哩1...
黑科技ai(德州wpk德州)外... 黑科技ai(德州wpk德州)外挂透明挂辅助器(透视)一直真的是有挂(有挂秘笈)-哔哩哔哩1、德州wp...
黑科技存在(aapoker开发... 黑科技存在(aapoker开发)外挂透明挂辅助ai代打(软件透明挂)总是真的有挂(有挂神器)-哔哩哔...
黑科技黑科技(wpk安卓版)外... 黑科技黑科技(wpk安卓版)外挂透明挂辅助设备(透视)一贯真的有挂(有挂方式)-哔哩哔哩1、下载好w...
黑科技攻略(xpoker)外挂... 黑科技攻略(xpoker)外挂透明挂辅助下载(辅助挂)真是是真的有挂(有挂助手)-哔哩哔哩1、xpo...
黑科技辅助(wpk德州ai机器... 黑科技辅助(wpk德州ai机器人)外挂透明挂辅助AI(透视)原来真的是有挂(有挂教程)-哔哩哔哩;1...