Global Variables to specify a starting Activity
I need to create some global android variables. Some posts here suggested me to do something like this:
public class MyAppName extends Application {
String foo;
//then, to create setters and getters...
}
and, to add android:name=".MyAppName" to manifest.
But now I am struggling with some basics that I missed along the way while trying to learn android.
My starting activity wa开发者_开发百科s named MyAppName. Now, of course I had to rename it, for example: MyStartingActivity.
The question is how do I start my MyStartingActivity. Where do I specify this activity as starting activity? Can I set some other activity to be the starting one?
I tried to StartActivity in OnCreate method of my application, but my app would force close every time.
Your Android Manifest is where you define the activities used by your application, and where you define which ons is your Main activity.
In order to define an activity as being your main, you need to make the intent filter of your activity look like this, in the manifest file:
<activity android:name="your.activity.name"
... >
<intent-filter ... >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
精彩评论