在窗口管理器中启动新活动

时间:2014-01-30 12:48:41

标签: android android-intent android-activity handler runnable

我想开始一项新活动,该活动会播放来自源的直播。当我开始活动时,它会在整个屏幕上播放内容。我想在一个小视图中显示流的内容,这是一个surfaceview。我通过使用运行runnable等的处理程序来完成此操作。我就是这样做的:

//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,该处理程序在表面视图上呈现流上播放的内容。我是这样做的:

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);

一旦runnable开始在处理程序上运行,我在设备上执行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-Fragment

致电UI-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();
            }

1 个答案:

答案 0 :(得分:0)

我怀疑我是否理解你的问题。也许你可以尝试使用没有UI的片段来启动线程而不是活动。