1. Download our Official Android App: Forums for Android!

Apps How to create a sub-activity

Discussion in 'Android Development' started by expoxiao, Mar 14, 2011.

  1. expoxiao

    expoxiao Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Mar 14, 2011

    Mar 14, 2011
    4
    0
    5
    Hi

    How to create a sub-activity in ECLIPSE which is in the same package with main activity or peer activity?
     

    Advertisement

  2. JamTheMan

    JamTheMan Well-Known Member
    Rank:
    None
    Points:
    38
    Posts:
    136
    Joined:
    Dec 16, 2010

    Add a new class that extends Activity?

    Or what do you mean by sub-activity?
     
  3. miXer

    miXer Android Enthusiast
    Rank:
    None
    Points:
    53
    Posts:
    313
    Joined:
    Aug 12, 2010

    Aug 12, 2010
    313
    51
    53
    Norway
    If you mean, how to make a new .java file with the other .java files in your package, here goes:
    - Right click the package where you want the .java file to be stored
    - Click New
    - Click Class
    - And in the Name field, put in the name of the class
     
  4. expoxiao

    expoxiao Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Mar 14, 2011

    Mar 14, 2011
    4
    0
    5
    Thanks for reply. I used this procedure to create a main java file and other two class in the same package. In mail java class i have two calls of Intent to revoke the other two class. The compile is correct and load the apk activity is success. But when I try open the application in emulator, it display the application is stopped unexpectedly.

    I don't know what is the reason for this issue. Could you please give me hints.

    Thanks
     
  5. miXer

    miXer Android Enthusiast
    Rank:
    None
    Points:
    53
    Posts:
    313
    Joined:
    Aug 12, 2010

    Aug 12, 2010
    313
    51
    53
    Norway
    We need to see the exception thrown in logcat and the code which generates the exception.

    - Open logcat: Window > Show view > Other, Android > Logcat
    - Start app in emulator
    - Take picture/screenshot/whatever of the exception thrown in logcat from the app
     
  6. expoxiao

    expoxiao Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Mar 14, 2011

    Mar 14, 2011
    4
    0
    5

    The screenshot jpeg is not visible on reply
     
  7. expoxiao

    expoxiao Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Mar 14, 2011

    Mar 14, 2011
    4
    0
    5
    Please see the attached jpeg file for exceptions I grabbed
    The code of creating these exceptions are following:

    import android.app.TabActivity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.widget.TabHost;

    public class IntentTabsdemo extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TabHost host=getTabHost();
    host.addTab(host.newTabSpec("one").setIndicator("CW").setContent(new Intent(this, CWBrowser.class)));
    host.addTab(host.newTabSpec("two").setIndicator("Android").setContent(new Intent(this, AndroidBrowser.class)));
    }
    }

    Thank you for your reply
     

    Attached Files:

  8. miXer

    miXer Android Enthusiast
    Rank:
    None
    Points:
    53
    Posts:
    313
    Joined:
    Aug 12, 2010

    Aug 12, 2010
    313
    51
    53
    Norway
    It says the problem is on line 14 and it cant find the activity. Have you added all activities to AndroidManifes.xml?
     
    expoxiao likes this.
  9. JamTheMan

    JamTheMan Well-Known Member
    Rank:
    None
    Points:
    38
    Posts:
    136
    Joined:
    Dec 16, 2010

    #( Also my first thought... All activities that are used by your app have to be registered in the Manifest.xml fil!!!

    Like this:

    Code (Text):
    1.  
    2. <activity
    3.       android:name=".ActivityClassName"
    4.       android:label="@string/activities_header"
    5. />
     
    expoxiao likes this.

Share This Page

Loading...