Start new activity in window manager
Asked Answered
B

1

1

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();
            }
Bakery answered 30/1, 2014 at 12:48 Comment(0)
I
0

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.

Illness answered 30/1, 2014 at 13:7 Comment(10)
In short, I want to start an activity in a smaller display of the current activity, which will be a surfaceviewBakery
So create an activity, 2 Fragments MainActivity starts with app, have a layout as per your requirement. The first fragment will do the display. Use the second fragment without UI to start the new thread. The view doesnt change and thread can update the UI as required using handlers or maybe directly since its a surfaceview.Illness
I have tried what you have suggested here, started the activity from a non-UI fragment which has its own layout. But whenever, the activity is started in oncreateview it runs on the whole screen rather then the layout of fragment defined in the xml..Bakery
I think i didnt convey my message properly. MainActivity( i assume this is the activity that starts when the app launches) will have 2 fragments, 1 with UI and 1 without. You can design the layout as required and show it. Then use the fragment without UI to start the thread. Please check the linkIllness
I have followed the article provided by you.. refer to the edit in the question of what I have tried now.. its still not working..Bakery
@Bakery you are still starting a new activity in the OnActivityCreated method. This will launch a new activity and replace the view with its layout. I suggest that you start your second fragment (the one without UI) to start the thread so that the the UI wont change. Then once the thread starts you can update the UI as required.Illness
I am now calling the non-ui-fragment from the ui-fragment.. refer to the edit made..Bakery
why are you starting a new activity inside onActivityCreated ?Illness
Where should I start the activity then?Bakery
let us continue this discussion in chatIllness

© 2022 - 2024 — McMap. All rights reserved.