Search code examples
androidactionscript-3airyoutube-apiair-native-extension

MouseEvent not dispatched after launching a new activity from ANE


I'm trying to launch a new activity from an Air Native Extension for Android function:

public FREObject call(FREContext context, FREObject[] args)
{

    try {
        Context contextApp = context.getActivity().getApplicationContext();

        Intent intent = new Intent(contextApp, DumbActivity.class);

        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        contextApp.startActivity(intent);

    }

The activity is launched successfully, but the MouseEvent.Click I added to the air app stage stopped working. I also tried to launched it using context.getActivity().startActivity(); same results.

UPDATE: Ok, so I understand I have to use the current activity. Problem is that I'm trying to use YouTube API to display the player. In many of their examples you need to extend an activity to use it.

So that's what I implemented to avoid using a new activity:

        playerView = new FrameLayout(activity.getApplicationContext());
        playerView.setId(R.id.player_view);

        playerFragment = YouTubePlayerFragment.newInstance();
        playerFragment.initialize(DeveloperKey.DEVELOPER_KEY, this);
        activity.getFragmentManager().beginTransaction().add(R.id.player_view, playerFragment).commit();

        container.addView(playerView, 640, 360);

It works OK when I launch it from native, but with the ANE, when I hit the play button on the player, it doesn't display the video, only sound.

With the separate activity the player worked fine but no Air interaction :\


Solution

  • When you launch another Activity, that Activity will take over the input and occupy the entire screen.

    If you are looking to keep functionality of the existing AIR application then you shouldn't launch another Activity but look into adding a View to the current Activity.

    To add a View v, using LayoutParams params to the AIR application you can use something like the following:

    ViewGroup fl = (ViewGroup)context.getActivity().findViewById(android.R.id.content);
    fl.addView( v, params );