New to Android Studio , Splash Screen Error - java

I am new to Android Studio and to the OS and have been designing an application, I tried to add a splash screen to my application after creating the splash screen and adding it to my manifest file but I keep getting this error:
Could not identify launch activity: Default Activity not found Error
while Launching activity
The tutorial I followed to get the splash screen provides no insight to correcting this error.
Below is my entire manifest file if someone could correct me I would be grateful.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="gui.prog">
<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">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".Display" ></activity>
<activity android:name=".Signup" ></activity>
<activity android:name=".Splash">
<intent-filter>
<action android:name="android.intent.category.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>

Just copy paste file,
<?xml version="1.0" encoding="utf-8"?>
<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"/>
<activity android:name=".Display" ></activity>
<activity android:name=".Signup" ></activity>
<activity android:name=".Splash">
<intent-filter>
<action android:name="android.intent.category.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
It will work, as currently it is unable to know which activity is initial one.

What I like to do for a 'SplashActivity' is set my 'MainActivity' as a regular activity, and set my 'SplashActivity' as the default activity that will begin on launch.
My AndroidManifest.xml:
<activity android:name=".Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" ></activity>
Then in my SplashActivity's 'onCreate' method:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Thread timerThread = new Thread(){
public void run(){
try{
sleep(2000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
}
}
};
timerThread.start();
}

you cant put two intent filters in the android manifest file if you want to launch app with spalsh screen activity you have to put the intent filter in the splash activity

Related

Arrange activities in android studio

I have a splash screen in my project it opens first with intent filter. After that it opens the main activity. But i created new activity that should be opened next to splash screen how to do that?
I have created three activities for example splash screen, main activity, login screen, Splash screen first opens next to that i need to open the login screen next only main activity.
xml code
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#mipmap/ic_main"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_main_round"
android:supportsRtl="true"
android:theme="#style/Theme.WeatherApp">
<activity
android:name=".SplashScreen"
android:exported="true"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden"
tools:ignore="LockedOrientationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoginActivity"
android:exported="false"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".HomeActivity"
android:exported="false"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden"
tools:ignore="LockedOrientationActivity" />
</application>
There are few ways to achieve this. This is one of my way.
First, at your AndroidManifest.xml, make sure you make your SplashActivity becomes your launcher. Then, at the onCreate method for your SplashActivity, do some delay, checking some stuff, is this user login or not. Last, go to next activity.
<activity
android:name="company.com.ui.SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
new Handler().postDelayed(
new Runnable() {
#Override
public void run() {
Intent intent = new Intent(SplashScreen.this, Login.class);
finish();
}
},
4000);

Intent is not working at Onboarding Screen

I tried cleaning up and rebuild the project but none of them worked
next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
viewPager.setCurrentItem(mCurrentpage+1);
if (mCurrentpage == mDots.length-1) {
Intent login = new Intent(OnBoardingActivity.this,LoginActivity.class); //*showing unable to find class LoginActivity*
startActivity(login);
}
}
});
Here is my AndroidManifest.xml
<activity android:name=".OnBoardingActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You need to add another activity in your AndroidManifest.xml file which is LoginActivity.
<activity android:name=".LoginActivity"/>
Add this under OnBoardingActivity in your manifest like the following.
<activity android:name=".OnBoardingActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LoginActivity"/>
You need to LoginActivity extends with AppCompatActivity. And also declare in AndroidManifest.xml file.
public class LoginActivity extends AppCompatActivity {}
And add in your AndroidManifest.xml
<activity android:name=".LoginActivity"/>
From your code and your manifest file. It is clear that you didn't add LoginActivity in your AndroidManifest.xml file
You need to add LoginActivity in your AndroidManifest.xml like this below code.
<activity android:name=".LoginActivity"/>
Full source code of the following manifest will be looked like this below code.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="">
<application
android:name=".MyApp"
android:icon="#mipmap/ic_launcher">
<activity android:name=".OnBoardingActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LoginActivity" />
</application>
</manifest>

Android Studio Not Finding Main Activity

I created a new class in my project called UserTypeSelection.java and wanted to set it as the main activity which launches when I run the app. I've changed the manifest file to contain an intent filter and also tried editing the configurations to set it as the default activity, however I keep receiving the error:
Error running app: The activity must be exported or contain an intent-filter
My manifest file is as follows:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.XXXXX.computerscienceinduction">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".UserTypeSelection" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<activity android:name=".RegistrationActivity"></activity>
<activity android:name=".MainActivity" />
<activity android:name=".LoginActivity" />
<activity android:name=".ProfileActivity" />
</application>
</manifest>
How can I resolve this issue. Any help is appreciated, thank you.
You are closing your activity xml tag before you have specified the IntentFilter.
Change your declaration to this.
<activity android:name=".UserTypeSelection" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
UserTypeSelection must be activity and it must be using intent filters you have not closed activity after intent filter it is closed before.
Try this,
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.XXXXX.computerscienceinduction">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".UserTypeSelection">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".RegistrationActivity"/>
<activity android:name=".MainActivity" />
<activity android:name=".LoginActivity" />
<activity android:name=".ProfileActivity" />
</application>
</manifest>

android.permission.RECEIVE_BOOT_COMPLETED does not launch activity at boot

I have a BootUpReceiver class which I'm attempting to use with RECEIVE_BOOT_COMPLETED to launch an Activity when the device boots. The problem is - it does not seem to do so when I launch the app then restart the device.
I have verified there is no issue running Activity1.java - the issue lies either in the Manifest or the BootUpReceiver class but I'm not sure exactly why it will not launch after rebooting.
BootUpReceiver.java:
public class BootUpReceiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, Activity1.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.com.idg.voiscphone"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.idg.voiscphone.Activity1"
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="com.idg.voiscphone.Activity2"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.idg.voiscphone.Activity3"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.idg.voiscphone.Activity3a"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.idg.voiscphone.Activity3b"
android:label="#string/app_name" >
</activity>
<receiver android:enabled="true" android:name=".BootUpReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>
Example Source:
http://androidrocksonmobility.blogspot.com/2012/01/how-to-create-auto-start-android.html
Remove android:permission="android.permission.RECEIVE_BOOT_COMPLETED" and try again.
Beyond that, there is no requirement that your activity appear in front of any other activity that might be started around the same time, such as the home screen.

My app doesn't show on emulator, when I run the project

when I try to run the project it installs successfully on an emulator, but emulator does not show my app launcher icon in its app menu. but however it shows my app in installed apps in setting>applications>manage applications>all apps , so that means that an app was installed. but it didn't run.
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.thenewboston.travis"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.thenewboston.travis.SPLASH" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Main"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.thenewboston.travis.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Menu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.thenewboston.travis.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Make sure your starting activity has its intent-filter declared properly in your manifest to be shown in the launcher.
Assuming you want "Splash" to be your main activity change its declaration to this (specifically the intent-filter action)
<activity
android:name=".Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Your intent filter action was not part of the android defaults (and what launchers normally look for). Only launchers that were designed to look for the action "com.thenewboston.travis.SPLASH" would see your activity
<activity
android:name=".Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.thenewboston.travis.SPLASH" /> //try "android.intent.action.MAIN" here//
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Categories

Resources