首页 > 代码库 > Activity转化成View

Activity转化成View

1.LocaActivityManager am = new LocalActivityManager(Context,true);

2.Window window = am.startActivity("tag",new Intent());

3.View view = window.getDecorView();


接下来一定要在3个生命周期函数里调用如下方法,否则会抛出异常:java.lang.IllegalStateException: Activities can‘t be added until the containing group has been created.

onCreate()方法里调用am.dispatchCreate(savedInstanceState);


onPause()方法里调用am.dispatchPause(true);


onResume()方法里调用am.dispatchResume();

本文出自 “严富坤-编程技术” 博客,请务必保留此出处http://kinbos.blog.51cto.com/2092114/1544869

Activity转化成View