How to pre-load on boot all activities in android - android

I'd like to solve a "too much waiting" problem. Hi to everybody :)
The case is that i've an application with a main menu that has 2 buttons. I'll paste the manifest here so you can see what I'm talking about.
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="razvitrance.administradorcontraseas.PantallaPrincipal"
android:label="#string/title_activity_pantalla_principal"
android:windowSoftInputMode="adjustResize|stateHidden" >
</activity>
<activity
android:name="razvitrance.administradorcontraseas.PantallaPrincipalAdministrar"
android:label="#string/app_name"
android:windowSoftInputMode="adjustResize|stateHidden" >
</activity>
<activity
android:name="razvitrance.administradorcontraseas.PantallaAyuda"
android:label="#string/title_activity_pantalla_ayuda"
android:windowSoftInputMode="adjustResize|stateHidden" >
</activity>
<activity
android:name="razvitrance.administradorcontraseas.PantallaAdministraroGenerar"
android:label="#string/title_activity_pantalla_administraro_generar"
android:windowSoftInputMode="adjustResize|stateHidden" >
</activity>
<activity
android:name="razvitrance.administradorcontraseas.PantallaPrincipalGenerar"
android:label="#string/title_activity_pantalla_principal_generar"
android:windowSoftInputMode="adjustResize|stateHidden" >
</activity>
<activity
android:name="razvitrance.administradorcontraseas.SplashScreen"
android:label="#string/title_activity_splash_screen"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
My main menu called .PantallaPrincipalAdministraroGenerar has 2 buttons and each of them call the new .PantallaPrincipalAdministrar and .PantallaPrincipalGenerar activities.
Well, my problem is that when I push the first of them, it takes no time to show the activite because it seems that that activity is already loaded, but when I push the second one the .PantallaPrincipalAdministrar takes too long until it appears on front and I do see on android studio's console how it is loading and creating all the files & allocating all the memory.
Is there any way I can preload all my activities in the boot of the app or while the splashscreen??
Thank you so much.

Luckily you cannot really. And you are most likely addressing problem in wrong place - if your activity takes too long to start check what you are doing in onCreate(), offload some tasks to background thrads, rework your ui, use Fragments, use lazy initialization etc, etc.

Related

Android - Back stack is not maintained when app is moved to background and bring to foreground

I am having 3 activities in my app and the flow is like A->B->C. When I was in activity C, I moved the app to background by pressing the home button. I brought the app to foreground again and it showed activity C as expected. When I press back key, it's closing the app and B and A are not shown.
I put the launch mode for A, C as single instance and for B, nothing is specified. I want to have one instance for all my activities. I have tried by changing the launch mode to single task(with permutation and combinations of all activities) and it didn't work.
Here is my manifest looks like for activity declaration
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
tools:ignore="GoogleAppIndexingWarning"
android:roundIcon="#mipmap/ic_myway_circular_launcher"
android:supportsRtl="true"
android:theme="#style/AppTheme.NoActionBar">
<activity
android:name="A"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="B"
android:windowSoftInputMode="adjustPan" />
<activity
android:name="C"
android:launchMode="singleInstance"
android:windowSoftInputMode="adjustPan"/>
</application>
Can someone tell me how to maintain the back stack always even when the app is opened from background?
Thanks in advance.
you can specify the parent(previous Activity) of any activity in the Manifest
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
tools:ignore="GoogleAppIndexingWarning"
android:roundIcon="#mipmap/ic_myway_circular_launcher"
android:supportsRtl="true"
android:theme="#style/AppTheme.NoActionBar">
<activity
android:name="A"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="B"
android:windowSoftInputMode="adjustPan" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".A"/>
</activity>
<activity
android:name="C"
android:launchMode="singleInstance"
android:windowSoftInputMode="adjustPan">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".B"/>
</activity>
</application>
After a lot of research, I found that it's the problem with the launch mode. As per Android documentation, for this mode, the system doesn't launch any other activities into the task holding the instance. The activity is always the single and only member of its task
But I wonder the issue is only coming when the app brought to foreground from background. If it is continuously running on foreground, issue is not there.
Finally, I changed it to default mode and it's working now.

Android: declaring particular activity as the launcher activity

I am just starting with android and trying to alter my android manifext .xml file such that a particular activity is launched first. My code is as follows:
<?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=".CrimeListActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".CrimeActivity">
</activity>
</application>
I have a CrimeListActivity java class which simply should display an empty activity. However, it continues to default to displaying the activity that was specified in the manifest originally. ( In this case, .CrimeActivity.
It's hard to be more specific without posting too much code so I'm hoping someone could give me a couple pointers on where to start poking around when issues like this arise.
Thanks!

Application was returning to First Activity

I have an application that works like the UBER, it happens that when you're going on a run, the screen where the passenger accompanies the driver moving up to him, when the user will open other applications and attempt to return to the app by clicking on the main icon of the application that is in the launcher, the application returns to the first screen and not to the screen that was previously being screen is lost ...
My manifest.
<application
android:name=".Application"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:screenOrientation="portrait"
>
<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=".ui.RaceActivity" android:screenOrientation="portrait"></activity>
</application>
It is because you had used finish() in your java coding as i know if you use finish() for activity then it always finish your activity and when you will open app then it will start it from first screen .

action bar not showing extending from a different module

I've created a :core module that stores some of my basic activities, some of these should show an actionbar, in the manifest I've something like this:
<activity
android:name=".components.home.HomeActivity"
android:theme="#android:style/Theme.Holo.NoActionBar">
</activity>
<activity
android:name=".components.activities.ContactsActivity"
android:theme="#style/AppTheme.TranslucentActionBar" >
</activity>
I don't understand why but now that I've created another module :extension that includes :core, the actionbars in that activities seems to not show.
The manifest of extension is very simple:
<application
android:name=".App"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:replace="android:icon" >
<activity
android:name=".components.activities.TestActivity"
android:label="#string/title_activity_test" >
</activity>
<activity
android:name=".components.home.WelcomeActivity"
android:label="#string/title_activity_welcome"
android:theme="#style/AppTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Usually this is a problem that concerns themes, but to me everything seems fine, I don't understand why it works when I build simply :core, but it doesn't work when building :extension project
I've spent too much time when the answer was easy.
Pressing Ctrl+click made me see how the theme was made, I've simply switched parent to the old layout.
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">

How to insert an android activity into the manifest given in a tutorial?

I am very new to android development with eclipse, and I encounter dozen of errors and problems. Here is the next one:
I am following an android tutorial given here in order to set up the action bar. In this tutorial is says to insert an activity as follows:
<activity android:theme="#style/Theme.AppCompat.Light" ... >
Can I just put this line into the xml manifest file?
<activity android:theme="#style/Theme.AppCompat.Light">
Or do I need to replace the '...' by something more useful?
Please read the docs: activity-element
The activity's name is required, so you would need to have:
<activity android:theme="#style/Theme.AppCompat.Light" android:name="MyActivity">
Other than that, you are not required to add any other attributes.
Although be sure to place the activity element within the proper place in your xml. It should be contained in your application block:
<application android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#android:style/Theme.Holo.Light">
<activity android:name="MyActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
Unless you really want your app to work under API levels under 3.0 then you have to add it like this.
android:theme="#style/Theme.AppCompat.Light"
Inside your already defined activity in your manifest (the one that has the intent filter and other declarations).
otherwise you dont have to add that at all.
This is one example.
<activity
android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.Light"
android:screenOrientation="portrait"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and this is another
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme=#style/Theme.AppCompat.Light"" >
<activity android:name=".DetailActivity"
android:label="#string/app_name" >
</activity>
The second way you posted is just fine, be sure to close the activity tag so it looks like <activity android:theme="#style/Theme.AppCompat.Light"></activity>
Also, if you're using eclipse, it is easier to go into the AndroidManifest and under the Application tab scroll to the bottom where there's Application Nodes and then add your view from there. Eclipse will auto generate the correct code in the xml file.

Categories

Resources