Android launch other activity before launching splash activity - android

I'm developing an application in android, where the app starts with a splash screen. I declared the splash activity as launcher activity in the manifest, but when I start my app, the launcher always shows up a grey activity with no content instead of the actionbar with the title of my app. The splash activity always comes up after one or two seconds.
Can anyone explain this behavior to me?
Here's my manifest:
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:logo="#drawable/navigation"
android:theme="#style/Theme.Sherlock.Light" >
<activity
android:name="de.test.basic.SplashActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity></application>
And here's the onCreate() method of the SplashActivity:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.spash_screen);
img = (ImageView) findViewById(R.id.imageView1);
img.setImageResource(R.drawable.splashscreen);
getActionbar().hide();
slideMenu.setSlidingEnabled(false);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
startActivity(new Intent(SplashActivity.this,
OtherActivity.class));
overridePendingTransition(android.R.anim.fade_in,
android.R.anim.fade_out);
finish();
}
}, SPLASH_DELAY);
}
Thanks for any help :)

Looks like its a bug in the api!
Simply add this in your starter activity declared in your manifest:
<activity
...
android:theme="#style/Theme.NoActionBar" >
<intent-filter>
...
</intent-filter>
</activity>
And if you are using ActionBarSherlock
<activity
...
android:theme="#style/Theme.Sherlock.NoActionBar" >
<intent-filter>
...
</intent-filter>
</activity>
Your question is rather similar than this one

Related

Two instances are created when launchMode is singleTask and called with different intents

I have created a sample custom launcher to check the behavior of launchMode and intents. Here is the MainActivity.java:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
protected void onResume() {
super.onResume();
}
#Override
protected void onDestroy() {
super.onDestroy();
}
}
Here is the AndroidManifest.xml contents:
<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:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:windowSoftInputMode="adjustPan"
android:screenOrientation="nosensor"
android:resumeWhilePausing="true"
android:taskAffinity=""
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
After installing the app when it is launched from app drawer, MainActivity starts with the intent - action as MAIN and category as LAUNCHER. Here it creates one instance. After that in Settings, if it is selected as the default launcher, MainActivity starts with the intent - action as MAIN and category as HOME. Here it creates another instance.
But if it is done in the reverse order, that is first from Settings and then from app drawer, it creates only instance.
So, why two instances are created?

App is installed twice

I have a shoppinglist App coded in Android-Studios. My app does have a splash screen. When I install the app, it is installed twice. When I uninstall one, the other one uninstalls too. I tried to delete the first intent filter on splashscreen, but then I did not have a splash screen anymore. I want my splashscreen to be remain. How to solve that? My manifest looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.projects.buylist">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".SplashScreen"
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=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
The app is only one.
You have simply two activities (and then 2 icons) that can work as launcher.
If you don't want, you have to remove this part in one Activity
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<category android:name="android.intent.category.LAUNCHER" /> this is telling android you want the activity to be visible from the app launcher. To solve it, remove the intent-filter from MainActivity.
Delete your main intent in XML and create something like this, which will run splashscreen and then open your MainActivity
public class SplashsScreen extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
new Handler().postDelayed(new Runnable(){
#Override
public void run() {
Intent mainIntent = new Intent(SplashsScreen.this, MainActivity.class);
SplashsScreen.this.startActivity(mainIntent);
SplashsScreen.this.finish();
}
}, 1500); // 1500 ms = 1.5 s
}
}

When I minimize the app that created, Why it starts all over again when opening?

I have a small app, then when I get out of the app (minimizo) and open again, it starts with the application of the home screen instead of opening the page you left off. That is, it starts the application all over again when it is minimized.
<?xml version="1.0" encoding="utf-8"?>
package="com.example.kevin.estudosbiblicos" >
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#mipmap/icon"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name">
</activity>
<activity android:name=".Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
First, you need to finish the splash activity after starting mainActivity.
new Timer().schedule(new TimerTask() {
public void run() {
Intent intent = new Intent();
intent.setClass(Splash.this, MainActivity.class); //Chamando a classe splash e a principal (main)
startActivity(intent);
finish();
}
}, 2000);
And in mainActivity , can you call finish() method in onpause method.
please show the whole mainActivity code
and you shouldn't use finish in onpause in your activity.
<activity ...
android:alwaysRetainTaskState="true"/>
Do this for all activities you want to save the state.

No activity found to handle Intent/no launcher activity found manifest file issue

Here's the problem guys, first i tried to run my application with Launch default activity as launch action (Run Configurations --> Android --> Launch action), the logcat kept telling me that it can't find the launcher activity and the application wouldn't even start, problem is i defined my launcher activity in the manifest file, but it's like it's not reading it at all.
So i tried to launch the splash activity by specifically telling it to run it through run configurations, it did launch but during the transition to the next activity it crashed again, the logcat says no activity found to handle intent, which again, I defined the way I did in other applications and worked alright there. Plase help it's a nightmare.
Here's the code for the MainActivity:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Thread timer = new Thread()
{
public void run(){
try{
sleep(6000);
} catch (InterruptedException e){
e.printStackTrace();
} finally {
Intent openStarting = new Intent("totaltrainer.com.WorkoutPlace");
startActivity(openStarting);
}
}
};
timer.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
And Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="totaltrainer.com"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<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="totaltrainer.com.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".WorkoutPlace"
android:label="#string/app_name" >
<intent-filter>
<action android:name="totaltrainer.com.WorkoutPlace" />
</intent-filter>
</activity>
<activity
android:name=".WorkoutHome"
android:label="#string/app_name" >
<intent-filter>
<action android:name="totaltrainer.com.WorkoutHome" />
</intent-filter>
</activity>
<activity
android:name=".WorkoutGym"
android:label="#string/app_name" >
<intent-filter>
<action android:name="totaltrainer.com.WorkoutGym" />
</intent-filter>
</activity>
</application>
</manifest>
use "totaltrainer.com.WORKOUTGYM" and so on
and below use this
<category android:name="android.intent.category.DEFAULT" />
Problem 1
logcat kept telling me that it can't find the launcher activity and
the application wouldn't even start
In your Manifest file, change below
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="totaltrainer.com.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
as
<activity android:name="MainActivity">
<!-- This activity is the main entry, should appear in app launcher -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
What happens when you define this Action and Category ?
The ACTION_MAIN action indicates this is the main entry point and does not expect any intent data.
The CATEGORY_LAUNCHER category indicates that this activity's icon should be placed in the system's app launcher. If the element does not specify an icon with icon, then the system uses the icon from the element.
These two must be paired together in order for the activity to appear in the app launcher.
Problem 2
the logcat says no activity found to handle intent
Your Manifest declaration seems fine.
In your activity class, change
Intent openStarting = new Intent("totaltrainer.com.WorkoutPlace");
startActivity(openStarting);
as
Intent openStarting = new Intent();
openStarting.setAction("totaltrainer.com.WorkoutPlace");
startActivity(openStarting);

Android activity added but never triggering onCreate()

I've added a new Activity, but the Toast message doesn't ever appear. It's not Toast specific though, it doesn't reach this class in general.
public class SecondActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// This should appear
Toast(..., "Inside of SecondActivity onCreate", ...).show();
}
...
My AndroidManifest looks like this,
<application
...
<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=".SecondActivity" ></activity>
</application>
you never call show() on your Toast
the launcher activity is MainActivity, but the Toast is inside SecondActivity. Did you add the logic to launch SecondActivity?
Edit:
From your Manifest I can read
<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>
So, when you execute your Application, the first activity launched will be MainActivity. Inside it you need to launch SecondActivity. For instance inside MainActivity's onCreate you could have something like:
Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);

Categories

Resources