0

I am begginner for android and want to develop something. I have a question about using more than one activity. I create two activity and invoke the others by intent. I use that code part :

 Intent intent = new Intent(MainScreen.this,GetNearestPlaceActivity.class);
 startActivity(intent); 

and it calls the other but i get an runtime error after invoking the second activity(application has sstopped unexpectedly). The second activity is dummy i just tried to achieve to intent. The code sample for second activity is :

public class GetNearestPlaceActivity extends Activity {

   public void onCreate(Bundle savedInstanceState)
       {
           super.onCreate(savedInstanceState);
            // setContentView(R.layout.main);   

       }
}

Is the problem is using same layout xml file? Do i have to use different xml file for every activity?

demongolem
  • 9,474
  • 36
  • 90
  • 105
oldTimes
  • 259
  • 3
  • 4
  • 13

4 Answers4

3

The log will tell you more info (either run adb logcat from the commandline, or look at the logcat tab in eclipse). Did you remember to add your new activity to the manifest file? every activity needs to be declared in the AndroidManifest.xml file.

And no, you don't need separate layout xml files for each activity, you can share layouts if you want.

superfell
  • 18,780
  • 4
  • 59
  • 81
2

Register second activity in your AndroidManifest.xml file.

<activity android:name =".SecondActivityName" />
Lucifer
  • 29,392
  • 25
  • 90
  • 143
0

check if you added the second activity to the manifest file correctly. If you are not sure whether you declared the second activity in the right format, try visiting and reading the things about setting up a second activity on this site:

http://developer.android.com/training/basics/firstapp/starting-activity.html

can't see any other errors with ur code with the information given. good luck.

0

You need to add the name of the Activity to your Manifest.

<activity android:name="com.example.packagename.ActivityName"></activity>

That should solve your problems.

Ilan
  • 38
  • 1
  • 8