How do i properly do multiple splash screens android - java

I want to make two splash screens for my android app. Only the second splash screen is visible whereas the first one isn't. Is what am trying to do possible? Here is my manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app">
<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">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</activity>
<activity
android:name=".SplashActivity1"/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<activity
android:name=".SplashActivity2">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
and here is my code for first splash screen
.........
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent i = new Intent(SplashActivity1.this,
SplashActivity2.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
and second Splash Screen
..................
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent i = new Intent(SplashActivity2.this, MainActivity.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}

Remove the intent filter from splashscreen 2 activity like in below code. other things are ok.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app">
<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
android:name=".SplashActivity1">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SplashActivity2">
</activity>
</application>
</manifest>

android:name="android.intent.category.LAUNCHER" should be give to only one Activity, which you want to call when app launches.
remove that from other Activities.
<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=".SplashActivity1">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SplashActivity2"/>
<activity android:name=".MainActivity"/>
</application>
I highly recommend you first learn How to deal with Intent_filter.

Try with this: Make Main activity as default one and splash screen as Main launcher
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app">
<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">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</activity>
<activity
android:name=".SplashActivity1"/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<activity
android:name=".SplashActivity2">
</activity>
</application>

Related

Add icon in Theme.AppCompat.Light

I'm using the Theme.AppCompat.Light in my android application and I would like to add an icon on the top left of the action bar. How can I do it? This is my Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.progettoium">
<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/Theme.AppCompat.Light">
<activity android:name=".ListaPrenotazioni"></activity>
<activity android:name=".ListaCorsi" />
<activity android:name=".ListaLiberi" />
<activity
android:name=".LoginSignup"
android:label="#string/title_activity_login_signup"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".Signup"
android:theme="#style/AppTheme.NoActionBar" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
you can add it programmatically with
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_action_refresh);
in your main activity

How to change first activity in Android Studio?

I want to change my first activity, first I have activity named MainActivity. And I add new activity named ActivityFirst. Surely I have to change AndroidManifest.xml. Previously I have androidManifest like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edmt.dev.androidsimsimi">
<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=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And after I add my new activity, also I change my androidManifest file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edmt.dev.androidsimsimi">
<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=".ActivityFirst">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I'm confused where I put the MainActivity after I add ActivityFirst. This my ActivityFirst.java:
public class ActivityFirst extends AppCompatActivity {
private Button mulai;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
mulai = (Button) findViewById(R.id.mulai);
mulai.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(ActivityFirst.this, MainActivity.class);
startActivity(intent);
}
});
}
}
You need <activity> tags for each Activity in your app's manifest file as mentioned here in the docs:
All activities must be represented by elements in the
manifest file. Any that are not declared there will not be seen by the
system and will never be run.
So in your case, it'd be like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edmt.dev.androidsimsimi">
<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=".ActivityFirst">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" />
</application>
</manifest>
In Android, The first Activity to show when a app is launched is tagged LAUNCHER in your manifest file.
All you need do to change the Launcher Activity is to add an intent-filter tag inside the activity tag.
So if your activity tag was self closing, you change it and add intent filter tag inside the tag.
Here is an illustration.
<activity android:name=".MainActivity" />
<activity android:name=".ActivityFirst">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The above code in your Manifest will make ActivityFirst the launcher activity,
while the below code will make MainActivity the launcher activity.
<activity android:name=".ActivityFirst" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
I hope this helps.

Application has stopped when launching the app with splash screen

I created a splash screen in my application suddenly when I ran the code it stopped. I created a splash screen in my code then it will redirect you to the menu. Is there something wrong with the android manifest xml?
Here's my manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kenneth.rusa">
<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.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".WelcomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.action.LAUNCHER">
</category>
</intent-filter>
</activity>
<activity android:screenOrientation="landscape" android:name=".Play">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
And this is the splash class code:
package com.example.kenneth.rusa;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
/**
* Created by Kenneth on 8/6/2016.
*/
public class WelcomeActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcomeactivity);
RunMe runme = new RunMe();
Thread t = new Thread(runme);
t.start();
}
class RunMe implements Runnable {
public void run() {
SystemClock.sleep(3000);
Intent intent = new Intent(WelcomeActivity.this,MainActivity.class);
startActivity(intent);
finish();
}
}
}
Please remove following lines from activities other than splash
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
Nvm I fixed it by changing the manifest file
Here's the updated code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kenneth.rusa">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.NoActionBar">
<activity android:screenOrientation="landscape" 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=".WelcomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:screenOrientation="landscape" android:name=".Play">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.default"/>
</intent-filter>
</activity>
</application>

Activity started but doesn't show up

Ok
I have manifest
<application
android:name=".App"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".ui.authorization.AuthActivity"
android:noHistory="true">
</activity>
<activity android:name=".ui.callsigns.SelectCallsignActivity"
android:launchMode="singleTop">
</activity>
<activity android:name=".ui.order.waitorder.WaitOrderActivity"
android:launchMode="singleTop">
</activity>
<activity android:name=".ui.balance.BalanceActivity"
android:noHistory="true"
/>
<activity android:name=".ui.splash.SplashActivity"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ui.order.gotorder.GoogleMapsActivity"/>
<activity android:name=".ui.order.gotorder.OrderDetailsActivity"
android:launchMode="singleTask"/>
<service android:name=".location.ServiceForLocation"/>
<service android:name=".network.newsocket.NewSocketService"/>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key"/>
<meta-data
android:name="io.fabric.ApiKey"
android:value="db0dc6f3ae8099a148926812fca7bd6cc29b4f4b"/>
</application>
...
Next start WaitOrderActivity
Intent intent = new Intent(getBaseContext(), WaitOrderActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME);
startActivity(intent);
Next from callback but in WaitOrderActivity I start OrderDetailsActivity
After all I call again startActivity(WaitOrderActivity) or OrderDetailsActivity.this.finish, anyway I will be in WaitOrderActivity again.
Trouble: in second time I see by logs what OrderDetailsActivity started, but I doesn't see that on the screen. I still see WaitOrderActivity. Why?

Android-Installing to device using eclipse install two instance of same app at once-error

Android-Installing to device using eclipse install two instance of same app at once-error
and it runs when just after installed using the eclipse but when I touch the once of the icon its not starting it shows me the android common error syaing unexpectedly stopped!! please help me??
This is the manifest I'm using(activities)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hunter99x"
android:icon="#drawable/icon"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".main" android:configChanges="orientation|keyboardHidden" android:theme="#android:style/Theme.NoTitleBar"
android:label="#string/app_name" android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".origine" android:configChanges="orientation|keyboardHidden" android:theme="#android:style/Theme.NoTitleBar"
android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.origine" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity `enter code here`android:name=".Gameover" android:configChanges="orientation|keyboardHidden" android:theme="#android:style/Theme.NoTitleBar"
android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LandingScreen" android:configChanges="orientation|keyboardHidden" android:theme="#android:style/Theme.NoTitleBar"
android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.VIBRATE"/>
</manifest>
I think the issue is because you have repeated
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
this for 2 activities. Try removing this and declare just 1 acivity as your main. Tjis may solve your issue.
Try this code inside the activities and check if it works:
#Override
public void onBackPressed() {
finish();
System.exit(0);
}

Categories