0

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>
Macin
  • 391
  • 2
  • 6
  • 20

3 Answers3

2

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.

Community
  • 1
  • 1
Shobhit Puri
  • 25,769
  • 11
  • 95
  • 124
  • Actually, I do not need to start one activity from another. First, I need to be able to access settings from apps list, by simply clicking on an app icon. Secondly, every time an android comes from sleep, my app should be launched before unlock screen. I have got the second part working - app launches before unlock scree, but now I am trying to add the first component ... and struggling to do so. – Macin Jul 29 '13 at 14:39
0

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.

0

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

Bram
  • 4,533
  • 6
  • 29
  • 41