Reputation: 391
I have an activity, which is launched every time user wants to unlock a phone (MainActivity).
I wish to add another activity to the app, which will launch every time user clicks an icon of an app, and will contain settings for the first activity. What is the correct way to set it in AndroidManifest.xml?
Currently my AndroidManifest file looks like this:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".BootCompletedReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name=".LockService"></service>
</application>
Upvotes: 0
Views: 1713
Reputation: 4613
The whole purpose of activities is that they can be re-used when the user opens the application again. You could create one activity and create a fragment everytime you open your app. Fragments do not have to be declared in your manifest. Your activity keeps track of the data. You are trying to add something dynamicaly (a unknown amount of activities) in a static xml-file (your manifest).
Just create a new fragment in your activity's onResume method.
http://www.vogella.com/articles/AndroidFragments/article.html
Upvotes: 0
Reputation: 26007
Define your activity in manifest like following:
<application>
...
<activity android:name=".YourNewActivity"></activity>
...
</application>
P.S:I assume that you activity is directly under the outermost package. if there are sub packages then you might need to use .subpackagename.YourNewActivity
.
Now in your MainActivity
, define a button inside who's onClickListener
, you can start your second activity YourNewActivity
using `Intents'. You might want to see this
How to start new activity on button click . Hope this helps.
Upvotes: 2
Reputation:
You can't tie an activity to a button click in the UI inside the manifest file itself. Just add a normal <activity>
and then ask for that activity to be called when you click the button.
Upvotes: 0