开始在窗口管理器的新活动(Start new activity in window manager)

2019-10-19 07:20发布

我要开始一个新的活动,该活动从播放源的实时流。 当我开始活动,它起着在整个屏幕上的内容。 我想要在一个小屏幕,这是一个surfaceview显示流的内容。 我用它运行一个可运行等的处理程序这样做。 这是我正在做它:

//new activity played from here
 Intent localIntent3 = new Intent("android.intent.action.MAIN");
//intent flag set to start a new task over the previous one
 localIntent3.setFlags(270532608);
 startActivity(localIntent3);

一旦该活动开始时,我运行在相应的处理程序,这使得在表面视图中的流播放的内容的可运行的。 这是我如何做到这一点:

Runnable handlerRuntv = new Runnable() {
        public void run() {
            try {
                MainActivity.this.surfaceView = new SurfaceView(
                        MainActivity.this.getApplicationContext());
                MainActivity.this.openSurfaceView();

                //method to scale the surface view to a smaller display
                MainActivity.this.setPipscale();

            } catch (Exception localException) {
                localException.printStackTrace();
            }
        }
    };

这是我在处理程序运行:

      this.handlerTV.postDelayed(handlerRuntv, 300L);

一旦可运行开始在处理器上运行,我做了back press设备上要带我去哪里的内容已经在播放先前的活动。

Question :我想直接启动面的尺寸显示器上的活动,即我不想让用户按后退按钮来查看数据流。 应该如何进行?

**EDIT:**

使用片段的片段开始的活动:

//In mainactivity.java
llFragment =(LinearLayout) findViewById(R.id.llfragment);
FragmentTransaction t = getFragmentManager().beginTransaction();
RunTVFragment fragment = new RunFragment();
t.add(llFragment.getId(), fragment, "fragment");
t.commit();

//llfragment in .xml
<LinearLayout
    android:id="@+id/llfragment"
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
</LinearLayout>

RunFragment.java将启动活动:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stub
        View v = inflater.inflate(R.layout.fragmentlayout, container, false);
        return v;
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onActivityCreated(savedInstanceState);
      Intent localIntent3 = new Intent("android.intent.action.MAIN");
      localIntent3.addCategory("android.intent.category.LAUNCHER");
      startActivity(localIntent3);
      this.handlerTV.postDelayed(handlerRuntv, 300L);
}

//fragmentlayout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/back"
    android:orientation="horizontal" >

  <FrameLayout
            android:id="@+id/surframelayout"
            android:layout_width="340dp"
            android:layout_height="280dp"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/textView1"/>

</RelativeLayout>

尽管如此,活动不会在所要求的画面的区域中开始/显示。 相反,它开始作为一个新的任务,比以往的活动..

EDIT II:

NONUIFragment的定义:

@Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onActivityCreated(savedInstanceState);
        ComponentName localComponentName2 = new ComponentName("mstar.tvsetting.ui", "mstar.tvsetting.ui.RootActivity");
          Intent localIntent3 = new Intent("android.intent.action.MAIN");
          localIntent3.addCategory("android.intent.category.LAUNCHER");
          localIntent3.setComponent(localComponentName2);
          localIntent3.setFlags(270532608);
          startActivity(localIntent3);
          this.handlerTV.postDelayed(handlerRuntv, 1000L);
    }

调用NONUI-FragmentUI-Fragment

@Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onActivityCreated(savedInstanceState);

         FragmentManager fm = getFragmentManager();

         // Check to see if we have retained the worker fragment.
         NonUITVFragment mWorkFragment = (NonUITVFragment)fm.findFragmentByTag("work");

         // If not retained (or first time running), we need to create it.
         if (mWorkFragment == null) {
             mWorkFragment = new NonUITVFragment();   //create instance of NON UI Fragment
             // Tell it who it is working with.
             mWorkFragment.setTargetFragment(this, 0);
             fm.beginTransaction().add(mWorkFragment, "work").commit();  //NON UI Fragment
         }
    }

调用UI-Fragment从我的主要活动:

if (savedInstanceState == null) {    //UI Fragement
                getFragmentManager().beginTransaction().add(R.id.llfragment, new RunTVFragment()).commit();
            }

Answer 1:

我怀疑我是否理解你的问题properly.Maybe您可以尝试使用一个碎片,无UI启动线程,而不是活动。



文章来源: Start new activity in window manager