Android: Changing the default acitivity removes access to application - android

I'm having an issue changing the default activity in my Android manifest
Initially, the MainAcitivity was the default activity but I would like it to change to the LoginActivity. When I do this however, the app disappears from the app drawer. The only way I can access the app information (uninstall, remove data etc) is via the application manager.
I've changed the tags on the LoginActivity entry in the manifest as suggested here but the issue is still there.
Here is a snippet of my current manifest:
<application
android:name=".ui.MyFirebaseApp"
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/title_activity_login"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
<activity
android:name=".ui.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="COMPANY_app_notification_click_action" />
</intent-filter>
</activity>
<activity
android:name=".ui.LoginActivity"
android:label="#string/title_activity_login"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
How would I get the application back to the app drawer?

Related

Android run 2 activities next to each other in task list

Is it possible within Android to run 2 activities side by side in task manager? I can now generate 2 separate icons and they both work properly but I can only open 1 Window at a time . As soon as I open the other icon, the current one is replaced with the new activity. I would have liked it to have its own screen if possible. I've tried various options but failed. Is it even possible within Android?
This is what my manifest looks like without the adjusments.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.allpics">
...
<application
android:allowBackup="false"
android:icon="#mipmap/ic_launcher"
android:usesCleartextTraffic="true"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.AllPics">
<activity
android:exported="true"
android:name=".MainActivity"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:exported="true"
android:name=".GalleryActivity"
android:label="Gallery"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
</application>
</manifest>
In the AndroidManifest, make sure to set the android:taskAffinity attribute of the element differently for each Activity. For example:
<activity
android:name="com.example.ActivityA"
android:label="Activity A"
android:launchMode="singleInstance"
android:taskAffinity="com.example.AffinityA" >
</activity>
<activity
android:name="com.example.ActivityB"
android:label="Activity B"
android:launchMode="singleInstance"
android:taskAffinity="com.example.AffinityB" >
</activity>

Set an Activity as the initial activity of an android app [duplicate]

This question already has answers here:
Change application's starting activity
(13 answers)
Closed 5 years ago.
In my new android sudio project I created two activities. The first is the MainActivity and the second is called SecondActivity. The second is more like a sort of menĂ¹. Logically, when the app starts, SecondActivity must appear as first.
In the manifest I declared both the activities but I don't know how to declare them correctly so that SecondActivity appears as the first activity in the application after I loaded it on my Android device.
This is my project's manifest :
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SecondActivity"> </activity>
</application>
Did you tried this, my friend
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"></activity>
<activity android:name=".SecondActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Two options...
1) Move the intent filter.
2) Switch the android:name property since ordering does not matter
Try this:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
</activity>
<activity android:name=".SecondActivity"> <intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter></activity>
</application>
The intent-filter tag let you choose trough the action wich activity will be the main.
Simply move the intent filters to the second activity like so:
...
<activity android:name=".SecondActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
The parts between the intent-filter tags (<intent-filter> and </intent-filter>) tell Android that this activity should be used when the launcher icon of your app is pressed (i.e. the initial activity).

When I start my app, it doesnt work. But if I include it through an icon, then everything works

I start the app on phone through Android Studio, it is shown an error in app. If I open application through an icon on my phone, then it works. I think that a problem in AndroidManifest.xml
P.S. If devices isn't in Lolipop, then it doesn't work anyhow.
UPD: I publish my app in Google Play. In Developer Console I received a notification message that an error in Main Activity, onCreate. But I don't found anything here.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.engineers.great.firstapp"
>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<!--Below MA which started at first. I can can return here, if I use a back button -->
<activity android:name="com.engineers.great.firstapp.MainActivity"
android:windowSoftInputMode="adjustResize"
android:configChanges="orientation"
android:screenOrientation="portrait">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
</activity>
<!-- It's not a main menu lol if you click from MA on "START" then you will be here -->
<activity android:name=".MainMenu"
android:windowSoftInputMode="adjustResize"
android:configChanges="orientation"
android:screenOrientation="portrait">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- Below from MA1_! to MA2 are questions and results of my test. I set intent extras in everyone. I don't know, maybe it's important -->
<activity android:name=".MainActivity1_1"
android:windowSoftInputMode="adjustResize"
android:configChanges="orientation"
android:screenOrientation="portrait">
</activity>
<activity android:name=".MainActivity1_2"
android:configChanges="orientation"
android:screenOrientation="portrait">
</activity>
<activity android:name=".MainActivity1_3"
android:configChanges="orientation"
android:screenOrientation="portrait">
</activity>
<activity android:name=".MainActivity2"
android:configChanges="orientation"
android:screenOrientation="portrait">
</activity>
<!-- It's many buttons with different results of test -->
<activity android:name=".Sociotypes"
android:configChanges="orientation"
android:screenOrientation="portrait">
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
You are not using any Launcher intent filter in first activity.
Add this in the activity you want to launch first :
<intent-filter>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN"/>
</intent-filter>

New activity seemed to reset default but XML unchanged

Can't figure this one out.
I added a second activity to a project in Android Studio. The second activity is now what launches on the emulator instead of the Main Activity.
Below is the XML in the manifest. Do I somehow need to declare the "get_started" activity as a child of the Main?
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".GetStarted"
android:label="#string/title_activity_get_started"
android:theme="#style/AppTheme.NoActionBar"></activity>
</application>
Try adding a DEFAULT intent filter to the MainActivity
<category android:name="android.intent.category.DEFAULT" />

Trouble understanding how to set my login activity to the launcher activity in the Android manifest

I want to change my manifest so that the Login Activity is the first activity to start on the phone. The login activity checks the sharedpreferences to see if a user has login info saved. If they do it logs them in. Im pretty sure I need an intent-filter in login activity with <category android:name="android.intent.category.LAUNCHER" /> but I dont get what I should put for the action.
Heres my manifest
<application
android:allowBackup="true"
android:icon="#mipmap/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>
<activity
android:name=".DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.incubatorcle.dinahealth.MainActivity" />
</activity>
<activity
android:name=".UserOnboardActivity"
android:label="#string/title_activity_user_onboard" >
</activity>
<activity
android:name=".LoginActivity"
android:label="#string/title_activity_login" >
</activity>
</application>
You need:
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
ACTION_MAIN action indicates this is the main entry point and does
not expect any intent data.
CATEGORY_LAUNCHER category indicates
that this activity's icon should be placed in the system's app
launcher.
Your MainActivity need to look like this:
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.yourpacgagename.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Your Login activity need to look like this:
<activity
android:name=".LoginActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
As your question is answered by #wariaten
Here is another way to do the login check
Add a third activity (where you check the SharedPreferences and launch the LoginActivity or the HomeActivity) and set it as the launcher as suggested by #wariaten

Categories

Resources