开始在窗口管理器新活动 [英] Start new activity in window manager
问题描述
我要开始一个新的活动,该活动对于从源实时流。当我开始的活动,它起着整个屏幕上的内容。我想在一个小屏幕,是一个surfaceview显示流的内容。我用它运行一个可运行的,因此在处理这样做。这是我怎么做的吧:
从这里 //新活动发挥
意图localIntent3 =新的意向书(android.intent.action.MAIN);
//意图标志设置为启动新的任务在previous 1
localIntent3.setFlags(270532608);
startActivity(localIntent3);
在这个活动开始后,我运行在各自的处理器,这使得表面上的看法上播放的流内容的可运行。下面是我如何做到这一点:
的Runnable handlerRuntv =新的Runnable(){
公共无效的run(){
尝试 {
MainActivity.this.surfaceView =新SurfaceView(
MainActivity.this.getApplicationContext());
MainActivity.this.openSurfaceView();
//方法来扩展表面以更小的显示
MainActivity.this.setPipscale();
}赶上(例外localException){
localException.printStackTrace();
}
}
};
这是我在处理程序运行:
this.handlerTV.postDelayed(handlerRuntv,300L);
在可运行开始在处理器上运行,我做了返回preSS
在设备上要带我去了previous活动,其中的内容正在播放。
问题
:我想直接在表面即缩放显示屏上开始活动,我不希望用户preSS后退按钮,看看流。应如何做?
**编辑:**
使用片段开始的片段活动:
//在mainactivity.java
llFragment =(的LinearLayout)findViewById(R.id.llfragment);
FragmentTransaction T = getFragmentManager()的BeginTransaction()。
RunTVFragment片段=新RunFragment();
t.add(llFragment.getId(),片段,片段);
t.commit();
// llfragment为.xml
<的LinearLayout
机器人:ID =@ + ID / llfragment
机器人:方向=横向
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT>
< / LinearLayout中>
RunFragment.java
将启动活动:
@覆盖
公共查看onCreateView(LayoutInflater充气,容器的ViewGroup,
捆绑savedInstanceState){
// TODO自动生成方法存根
视图V = inflater.inflate(R.layout.fragmentlayout,集装箱,假);
返回伏;
}
@覆盖
公共无效onActivityCreated(包savedInstanceState){
// TODO自动生成方法存根
super.onActivityCreated(savedInstanceState);
意图localIntent3 =新的意向书(android.intent.action.MAIN);
localIntent3.addCategory(android.intent.category.LAUNCHER);
startActivity(localIntent3);
this.handlerTV.postDelayed(handlerRuntv,300L);
}
//fragmentlayout.xml
< XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:背景=@可绘制/后退
机器人:方向=横向>
<的FrameLayout
机器人:ID =@ + ID / surframelayout
机器人:layout_width =340dp
机器人:layout_height =280dp
机器人:layout_alignParentRight =真
机器人:layout_below =@ + ID / textView1/>
< / RelativeLayout的>
不过,活动不启动/中所要求的画面的区域的显示。相反,它开始作为一个新的任务,在previous活动。
编辑II:
NONUIFragment的定义:
@覆盖
公共无效onActivityCreated(包savedInstanceState){
// TODO自动生成方法存根
super.onActivityCreated(savedInstanceState);
组件名localComponentName2 =新的组件名(mstar.tvsetting.ui,mstar.tvsetting.ui.RootActivity);
意图localIntent3 =新的意向书(android.intent.action.MAIN);
localIntent3.addCategory(android.intent.category.LAUNCHER);
localIntent3.setComponent(localComponentName2);
localIntent3.setFlags(270532608);
startActivity(localIntent3);
this.handlerTV.postDelayed(handlerRuntv,1000L);
}
调用 NONUI片段
从 UI片段
:
@覆盖
公共无效onActivityCreated(包savedInstanceState){
// TODO自动生成方法存根
super.onActivityCreated(savedInstanceState);
FragmentManager FM = getFragmentManager();
//检查,看看我们是否保留了工人的片段。
NonUITVFragment mWorkFragment =(NonUITVFragment)fm.findFragmentByTag(工作);
//如果不保留(或第一次运行),我们需要创建它。
如果(mWorkFragment == NULL){
mWorkFragment =新NonUITVFragment(); //创建非UI片段实例
//告诉它是谁正在与。
mWorkFragment.setTargetFragment(此,0);
fm.beginTransaction()加(mWorkFragment,工作)提交()。 //非UI片段
}
}
调用 UI片段
从我的主要活动:
如果(savedInstanceState == NULL){// UI Fragement
。getFragmentManager()的BeginTransaction()加(R.id.llfragment,新RunTVFragment())提交()。
}
我怀疑我是否理解你的问题properly.Maybe,你可以尝试使用片段没有用户界面,启动线程,而不是活动。
I want to start a new activity, the activity plays a live stream from a source. When I start the activity, it plays the content on the whole screen. I want to display the contents of the stream in a small screen which is a surfaceview. I am doing this by using a handler which runs a runnable and so on. This is how I am doing it:
//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);
Once this activity is started, I run the runnable on the respective handler, which renders the contents played on the stream on a surface view. Here is how I do this:
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 is how I run it on the handler:
this.handlerTV.postDelayed(handlerRuntv, 300L);
Once the runnable starts to run on the handler, I do a back press
on the device to take me to the previous activity where the content is already playing.
Question
: I want to start the activity directly on the scaled display of the surface i.e. I do not want the user to press the back button to see the stream. How should this be done?
**EDIT:**
Using fragments to start activity in a fragment:
//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
that would start the activity:
@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>
Still, the activity does not start/display in the region of the screen required. Instead, it is started as a new task, over the previous activity..
EDIT II:
Definition of 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);
}
Calling NONUI-Fragment
from the 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
}
}
Calling UI-Fragment
from my main activity:
if (savedInstanceState == null) { //UI Fragement
getFragmentManager().beginTransaction().add(R.id.llfragment, new RunTVFragment()).commit();
}
I doubt whether i understood your question properly.Maybe you can try using a fragment without UI to initiate the thread instead of the activity.
这篇关于开始在窗口管理器新活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!