App's application created but main activity is not create - android

My app is a Launcher.
start an app on launcher.
when my launcher is in background, from logcat I can see that Application is created but the main activity is not created.
public class LauncherApplication extends Application {
#Override
public void onCreate()
{
super.onCreate();
......
Log.d("TAG", "onCreated");
}
}
public class MyLauncher extends Activity {
.....
}
Manifest.xml
<application
android:name="com.launcher.LauncherApplication"
android:label="#string/application_name"
android:hardwareAccelerated="true"
android:process="android.process.acore"
android:largeHeap="true"
android:persistent="true" >
<activity
android:name="com.launcher.MyLauncher"
android:configChanges="mcc|mnc|keyboardHidden|keyboard|orientation|screenLayout|screenSize|smallestScreenSize|navigation|uiMode"
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:screenOrientation="portrait"
android:persistent="true"
android:allowBackup="true"
android:windowSoftInputMode="stateUnspecified|adjustPan" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY" />
</intent-filter>
</activity>
......
</Application>
MyLauncher is the main activity.
My question is:
when log prints "onCreated", that means my launcher is killed bo OS in background and LauncherApplication is restarted ?

Related

Two launcher activities creating two APKs

I recently added a splash-screen to my app and made it as launcher activity to display it when the app started, the manifest looks like,
<activity android:name=".LaucherActivity" android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And I have the MainActivity which is already a launcher activity in the manifest shown below,
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.TransparentTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> s
</intent-filter>
</activity>
So, this is actually creating two APKs, one for the splash and the other main activity. But I wanted the SplashActivity and MainActivity in the same APK running one after the other. How can I achieve that? I found many related questions but none of them are working for me.
Use <intent-filter> only once in manifest. like this
<activity android:name=".LaucherActivity" android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.TransparentTheme">
</activity>
public class LaucherActivity extends Activity {
private static int SPLASH_TIME_OUT = 3000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent i = new Intent(LaucherActivity.this, MainActivity.class);
startActivity(i);
finish();
}
}, SPLASH_TIME_OUT);
}
}
Remove this from you MainActivity.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Now call your MainActivity from your Splash Activity

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?

How to make activity launcher for different api version?

I'm building an kiosk App for two different versions: Android 6 and before.
When app started I have StartActivity and 2 Activities for different APK lvl, start this:
public class StartActivity extends AppCompatActivity {
#Override
protected void onCreate(#Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
startActivity(new Intent(this, MainActivityNew.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
} else {
startActivity(new Intent(this, MainActivityOld.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
finish();
}
}
MainActivityNew and MainActivityOld must be launchers (when button home is pressed he must call)
In Manifest file i write:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ng.lockergks">
<application
android:name="com.gks.locker.App"
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.NoActionBar.FullScreen">
<activity android:name="ru.gks.locker.ui.activity.StartActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".MainActivityOld"
android:launchMode="singleInstance"
android:screenOrientation="portrait"
android:stateNotNeeded="true">
<intent-filter>
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".MainActivityNew"
android:launchMode="singleInstance"
android:screenOrientation="portrait"
android:stateNotNeeded="true">
<intent-filter>
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".AppListActivity"/>
</application>
</manifest>
That is, when the application starts, check the version of the API, and depending on it, runs one way or the other activity which should be a launcher. On both versions it does not work. How to define such behavior?

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
}
}

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);

Categories

Resources