1. Download the #1 Android News App:   EarlyBird - News for Android
    Dismiss Notice

setContentView of Activity within Activities current View

Last Updated:

  1. tantonj

    tantonj New Member

    So I have my main activity. It starts out adding a custom SurfaceView called DrawView as the content view with

    DrawView drawview = new DrawView(parameters);

    This works great!... now my layout.main.xml is a layout with a video view which I am using to play my cutscenes. I am able to switch to this view by calling a method I made which switches the content view by


    which works fine when I am calling this method within the Activity. Only problem is I need to call this method from within DrawView! The method I made to switch to my cutscene is public and I do pass the Activity (named Draw) as a parameter of DrawView.

    So when I do call this method from within DrawView my game freezes and will subsequently crash! however it works when method is called locally?

    Why is this happening? anybody able to help? or maybe tried doing this before?

  2. jonbonazza

    jonbonazza Well-Known Member

    as long as you are passing an instance of Context to the method that is starting the activity (and that Context object is not null), then it should work.
    Can we see a copy of the log cat when it freezes, and also some code snippets?
  3. alostpacket

    alostpacket Over Macho Grande? VIP Member

    Yeah stack trace is crucial here, but I am wondering why you are calling setContentView on the custom SurfaceView (DrawView).

    I dont know the particular problem that is supposed to solve, but the more typical usage of setContentView would just be to layout your activity.

    So, in other words, you would only call setContentView(R.layout.main) once from onCreate() -- then you would put Custom SurfaceView in the XML for R.layout.main or you could add the view programatically via java after the contentView has been set.

    Would something like this not work for what you are doing?
  4. jonbonazza

    jonbonazza Well-Known Member

    It's perfectly acceptable to use setContentView() with a subclass of SurfaceView. In fact, when working with OpenGL, this is THE way to do it.

    However, I am lost when trying to understand the logic behind the OP's transitions. I simply don't understand what he is trying to accomplish, so I can't offer much help beyond, "Show me the logcat."

    alostpacket likes this.

Share This Page