THIS QUESTION IS SOLVED, PROVIDING ANSWER FOR FUTURE SO VISITORS BELOW
Context :
I am developing a default phone app. Which handles action.DIAL and action.CALL from My application as well as it handles these both intents from other apps too.
What is problem :
If my CallActivity is running ( if any call is ongoing ) then -
When i again try to open my app, it is presenting me CallActivity only.
And because of this i am unable to make another call by opening my app.
What manifest.xml looks like :
<application
android:allowBackup="true"
android:directBootAware="true"
android:fullBackupContent="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"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.CALL_BUTTON" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<activity
android:name=".CallActivity"
android:label="#string/title_activity_call"
android:process=":CallManager"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter android:priority="800">
<action android:name="android.intent.action.ACTION_CALL" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
</application>
What i found when searched for the said problem :
How can I launch an independent activity to my application as well as the application of phone launches the activity to make calls?
https://stackoverflow.com/questions/9458300/how-to-create-an-android-activity-and-service-that-use-separate-processes
What are my efforts taken :
You can note i tried android:process=":CallManager" attribute in manifest for my CallActivity
Did that solved the issue :
Nope. I am still unable to open my MainActivity, whenever CallActivity is running. But is caused the problem that now my call is not getting ended as this is completely another process it is unable to reference other calls which remain there in older process.
ANSWER
Did android:process was correct :
No not at all in this case, as it is used when our app memory usage increases over particular limit android starts caching its services and resources in order to avoid it developers generally use android:process which allows them another heap memory available with same heap size.
** What was problem :**
It was related to task and its affinities
Both activities needed to be separated for tasks and their affinities
like :
<activity
android:name="com.example.ActivityA"
android:label="Activity A"
android:launchMode="singleInstance"
android:taskAffinity="com.example.AffinityA" >
</activity>
<activity
android:name="com.example.ActivityB"
android:label="Activity B"
android:launchMode="singleInstance"
android:taskAffinity="com.example.AffinityB" >
</activity>
I must thanks #JayWozz for his answer over SO https://stackoverflow.com/a/45488126/9810130 and must appreciate #gabe-sechan for his sincere help and efforts and for giving his value-able time for this thread.
I think you're basically asking for a new stack of activities. Try launching the intent with FLAG_ACTIVITY_NEW_DOCUMENT| FLAG_ACTIVITY_MULTIPLE_TASKS That will launch the activity as if its a new set of activities, with its own separate listing in the recent apps list. See the definiton of these flags at https://developer.android.com/reference/android/content/Intent
Related
I have been trying deeplinking in a react-native application and trying to directly open a screen inside a navigator. I use react-native-deep-linking and react-navigation as libraries. Also nested navigators are used. Deeplinking works correctly except I have some problems with the android:launchMode property.
This is the results I get for each of the android:launchMode options.
android:launchMode="standard" - App opens using the deeplink but opens up an entirely new application.
android:launchMode="singleTask" - App opens using the deeplink. If I open the app using another link. App comes to the foreground but it directs to the previous link.
android:launchMode="singleTop" - App opens using the deeplink but opens up an entirely new application.
android:launchMode="singleInstance" - App opens using the deeplink but opens up an entirely new application.
If I remove the android:launchMode property, again the same thing happens as the "standard" mode because it is the default.
What option can I use to resolve this problem? Is there any #override that I can do inside the main activity?
Below is my AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.VIEW"/>
<data android:scheme="https" android:host="*.myapplive.com" android:pathPrefix="/"/>
<data android:scheme="https" android:host="*.myapp.com" android:pathPrefix="/"/>
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/>
</application>
Not sure if still relevant but may help someone in future.
The reason is that when activity is in any mode other than standard, re-opening the app from the background will not replace the original intent used to launch the app from the killed state. Instead, those new intents will be directed to the onNewIntent(Intent intent) method. There, you can call setIntent(Intent intent) in order to replace activity's intent with the new one.
You can override this method in your MainActivity. (Note that when overriding this method in React I had to make it public and not protected as I would usually do in Android. Not sure why yet)
Read more here - https://developer.android.com/reference/android/app/Activity#onNewIntent(android.content.Intent)
I'm having an issue with deeplinking in my application. When I click a url from my email and it prompts me to choose an application to open the link with, my app is listed twice. One version works and the other does not. Any suggestions?
Here's the snippet of code I think could be the issue:
<application
android:name="com.test.TestApplication"
android:allowBackup="true"
android:fullBackupContent="#xml/backup_rules"
android:resizeableActivity="false"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name="com.test.activity.LoginActivity"
android:configChanges="orientation"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize" />
<activity
android:name="com.test.activity.HomeActivity"
android:configChanges="orientation"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.MenuDrawer">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
When an intent is sent to the system to open another activity, the system applies the rules specified here to find which activities/services can receive that intent. If there is more than one activity there, then the user will be prompted with all the matching activities. In this case what you experience is that the intent sent can be received (based on intent filters) by multiple activities, depending on how it is defined in your manifest.
Possible Duplicate Deep linking and multiple app instances. I have implemented Deep Linking in my app. I have Splash activity that is launcher and MainActivity that handles the Intent as defined in manifest:
<application
android:name=".MyApplication"
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="#drawable/app_logo"
android:label="#string/app_name"
android:largeHeap="true"
android:theme="#style/AppTheme">
<activity
android:name=".ActivitySplash"
android:configChanges="orientation|screenSize"
android:label="#string/app_name">
<intent-filter>
<!-- Launcher activity -->
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ActivityMain"
android:alwaysRetainTaskState="true"
android:configChanges="orientation|screenSize"
android:exported="true"
android:label="#string/app_name"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="www.mywebsite.com"
android:pathPrefix="/something"
android:scheme="http" />
</intent-filter>
</activity>
<activity
android:name=".ActivitySignIn"
android:configChanges="screenSize|orientation" />
<activity android:name=".ActivitySignUp" />
</application>
I have set launch mode singleTask to handle onNewIntent(). Now what i want to achieve is that if user opens activity from DeepLinking and there is already some task going on in MainActivity I prompt user a dialog either he want to cancel current task and start new task (which is from deep linking). The issue is If i open another activity from MainActivity and user comes from DeepLinking Intent. Then it would kill the second activity and directly open MainActivity. What i want to achieve is that if app/activity is not running then Intent from DeepLink open as is. And if activity/app is already running then i prompt user to either close current task and perform DeepLink task/intent.
This doesn't really work the way you think it does. You are trying to use launchMode="singleTask", but since you haven't also set "taskAffinity", Android pretty much ignores your launchMode.
You should not need to use either of the special launch modes "singleTask" or "singleInstance" to get what you want.
Try using singleTop launch mode and see if this solves your problem. If ActivityMain is already open and you launch ActivityMain again using your deep-link, onNewIntent() should be called in ActivityMain.
You can also look at my answer to this question which describes a way to determine what Activity to show based on using a static variable to decide whether another Activity is in the stack or not.
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.
I am trying to learn Android.
I simply have Splash.Java and MainActivity.Java classes.
Before Splash.Java was the starting Action of my application.
Now I want to change it to MainActivity.Java.
Here is what I have done:
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name" android:theme="#style/AppTheme">
<activity android:name=".MainActivity" android:label="#string/title_activity_main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Splash" android:label="#string/title_activity_main">
<intent-filter>
<action android:name="com.example.anddappp.SPLASH" />
<category android:name="com.example.anddappp.DEFAULT" />
</intent-filter>
</activity>
</application>
I cleaned my Project, and I do not use "Run previously launched application" in Eclipse. But still the application starts with Splash.JAVA.
What am I doing wrong?
"Check in run configuration which activity is selected." This way android, or in this case eclipse knows which of your activities to start from.
In the future, if you know the answer to one of your questions feel free to answer it yourself. You will be able to accept your own answer in eight hours.
Thanks to shashank Kane for providing the answer