android app running multiple instances - android

When i download my app from store.
its installed on main screen, and on apps menu ( when i click the circle with 6 dots on it )
when i click from main screen it opens an app, and when i click from the other place..it opens a second app as well.
i need one app running only..
how can this be fixed?
my manifest
<application
android:name="dfsfsdp"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".StartupActivity"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

I think you aren't running multiples instances (if you are running multiple instances if fail of the mobile), or you see two applications open in the menu what you use to close the running apps (the recent applications menu)?
If you only see one maybe your are restarting the same instance. Look at your StartupActivity or post here to try help you.
If this don't help you, take a look at to read about the lifecycle of an Activity:
http://developer.android.com/training/basics/activity-lifecycle/index.html
Best regards.

Related

How to run a certain activity in Android Studio?

For instance, I have a few activities within one app, and in order to see a certain activity's UI or whatever, I need to run a certain activity that is not the launcher of the app.
One stupid way is to build a "door" for that activity in the launcher and go inside the activity from the door. However, Is there any better way to run a certain activity alone?
Very easy. Start by exporting the activity you need to run:
Add android:exported="true" in the Activity declaration in the Manifest. This is because am is an external application, and you need to export Activities to allow external application to start them.
Go to "Edit Configurations..." in the "Run" menu.
In the left pane, select your application. In the right pane, in the "General" tab, in the "Launch Options" section, there is a "Launch:" dropdown.
Select "Specified Activity", and enter the name of your activity as it appears in your Manifest.
You can create as many Configurations as you like, and name them according however you like, for example to indicate which activity is being started.
I am using Android Studio stable version 2.1.2 and there is one shortcut to do so. Just open the activity class you wish to run and right click on coding area, There is options to run and debug the particular activity as shown in below screen shot.
For windows use shortcut ctrl+shift+F10 and for mac use ctrl+shift+R. I have tested this in emulator and its working fine, didn't test in actual device.Works only for activity class and don't forget to put cursor in coding area by clicking on it. Also I am not aware whether this option available in older Android studio versions less than 2.1.2.
As mentioned in this answer, you can easily achieve that by giving the activity an action name in the manifest.xml of the app:
<activity android:name="Activity3" ... >
<intent-filter>
<action android:name="com.company.package.FOO"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
then create the following intent from anywhere in order to run this activity specifically:
startActivity(new Intent("com.company.package.FOO"));
After your clarification that the activity has to be run firstly when running the app instead of the launcher, you can achieve that by not setting the content of the launcher activity and instead create an intent that runs the wanted activity:
MainActivity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_layout); // remove this line
Intent intent = new Intent(ThisActivity.this, WantedActivity.class);
intent.putExtra("EXIT", false);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
Add exported true Manifest declaration of that activity.
Go to that activity, right click anywhere, go will get certain option with a 'Run XYZ Activity' option too. just run it
<activity android:name=".phoneVideo">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
First you need to have two or more activities in your app to start with. Let's say you want to go to a certain activity in your app to display first. May be for testing purposes or any other. Let's see how it can be done,
First you need to find the AndroidManifest.xml file. Its there under the manifests folder.
According to this first dispaly activity is MainActivity
Lets's say I want to make the home activity display first. So what I have to do is simply cut the intent-filter.../intent-filter and paste it within home activity. Like this
First Displaying Acivity is MainActivity according to this,
<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=".home">
</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>
When we want to make the home acivity display first simplay change it as this,
<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=".home">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
</activity>
</application>
This should work. Hope this will help
For my example, the specific activity was called Activity2 and the project was called ScreenSizes
1- Open the Android Manifest: app>manifests>AndroidManifest.xml
2- Change the activity section for the specific activity to include android:exported="true" like this:
<activity android:name=".Activity2"
android:exported="true">
</activity>
3- Open the java class of the specific activity: app>java>com.example.(your app name)>(specific activity)
in my case it was: app>java>com.example.screensizes>Activity2
4- Right click anywhere in the blank/white area of the Java file and select the option Run '(activity name)'
in my case it was: Run 'Activity2'

Why is my android app's behavior different according to devices?

Hello recently I made a simple Android puzzle game. It has two Activity classes. First Activity is for Menu options, second is for the Main game.
After pressing the Start button from Menu options of the first activity, the 2nd activity appears/starts. My problem is if i minimize the game from 2nd activity by pressing home button, and come back to the game, it starts from the first activity. And then if I press back button, the 2nd activity comes back.
Why does first activity come to the front when I left the app during 2nd activity? I have no idea why my first activity comes to front.
My manifest
<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="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.senzgames.superword.GameCore"
android:label="#string/title_activity_game"
android:screenOrientation="portrait"
android:parentActivityName="com.senzgames.superword.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.senzgames.superword.MainActivity" />
</activity>
</application>
Another thing my device is Sony Xperia E3 android 4.2.2 but I also test it on Samsung s3 it works fine on Samsung. It starts the same activity which I left on Samsung. Why is it acting differently on different devices? Thanks for help in advance.
Maybe you have activated the "kill all activities" option in development tools in your Sony Xperia E3 ?

Android application doesn't appear on recent apps list

i'm deploying an android application (Android 4.0.3) and when I press the home screen the application doesn't stay on the recent apps list. I've noticed that when I restart the application, it starts on the last screen i've navigated before press the home button. Anyone can help? Here is me Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="#drawable/logo_home"
android:allowBackup="true">
<activity
android:name="com.test.activity.CommunicatorActivity"
android:launchMode="singleTop"
android:label="" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.test.activity.InputActivity"
android:windowSoftInputMode="adjustPan|stateHidden">
</activity>
<activity android:name="com.test.activity.SettingsActivity"
android:windowSoftInputMode="adjustPan|stateHidden">
</activity>
<activity android:name="com.test.activity.OutputActivity"
android:windowSoftInputMode="adjustPan|stateHidden">
</activity>
</application>
</manifest>
I'm going to go out on a limb and suggest that this is your problem:
android:label=""
In your root activity CommunicatorActivity you've set the label to be an empty string. This label is used to identify your app in the list of available apps and because it is empty, this may be causing it not to show up in the list of recent apps.
Remove android:excludeFromRecents="true" from your manifest
You should use
android:label="your app_name"
2 things
Ok, there isn't something obvious in your manifest that should prevent it from appearing in your recents list.
1. Wrong identification
It's not always straight forward to tell which task contains your activity, using the GUI.
One of the possibilities is that an activity from some other app is on top of your task making you believe that your activity isn't there. Since, clearly it resumes to the last screen.
I suggest you to remove the single top temporarily and check the same.
2. Launcher modification
Has the launcher you use the standard launcher? Has the launcher or some other app modified the presentation or behavior of the recents screen (unlikely but worth a check)
For this, I suggest using a stock launcher or try the same app on a different phone or an emulator.
What would help is steps you followed and some screen shots of recents
screen and also of your app
I had the same problem.
The reason is that I had set android:label="" in manifest.xml.
I hadn't set android:launchMode="singleTop".
I declared on purpose android:label="" because I didn't find any better way to remove the title of the action bar from my main activity.
I turned android:label="app_name" again and everything now is OK; the app appears again in recent app list when pressing the home screen and doesn't start on the last navigated screen when restarting it.

How can I resume a running activity?

I made myself an app: a music player with automatic bookmarking :)
Problem:
If I go "back" to the home page and then try to run the app again, it creates a new instance whereas I want to continue. I might leave music running while I do other things and then I can't pause it or save it because I can't access it!
Failed Solutions:
I've tried singleTop, singleTask, singleInstance and they all don't work!
I can view running apps (Settings > Applications > Manage Applications > Running) but it only let's you "Force stop" them. How about "Bring to front"?! Also, when I finish() my app, I notice it's still "running"!
This site is very awesome and useful and this is my first question :) I looked for answers but couldn't find any that worked :(
Here's the manifest:
<application android:icon="#drawable/icon"
android:label="#string/app_name">
<activity android:name="Fire"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Back by default closes the activity. You can override this behaviour by catching BACK key, but in your case, you really need Service not activity to play music and control it. Activity is ment to be destroyed when you leave it on BACK really....
Read more here: http://developer.android.com/guide/topics/fundamentals/services.html

Android forcing full restart after an app is killed

Hello
My application works like this.
StartUpActivity is called first, which does a lot of the init stuff
Then it launches TvbTabActivity (TabActivity) that has other Activities as its tabs (e.g. BrowseActivity).
The problem that I am seeing is this - when a task-killer app is used to terminate my app on TvbTabActivity/Browse tab, and the app is relaunched again, the system forgoes the normal flow (StartUpActivity is not spawned), but instead restores the last visible activity directly (TvbTabActivity).
How can i force Android to ALWAYS run StartUpActivity first, so that it initializes the app?
Obviously, I dont have this problem when my app crashes on its own, lol, due to an exception, and is then relaunched again.
<application android:icon="#drawable/appicon"
android:label="#string/app_name" android:name="com.xyz.QPApplication"
android:debuggable="true">
<activity android:name=".activity.StartUpActivity" android:configChanges="locale|orientation"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".catalogue.BrowseActivity" android:configChanges="locale|orientation"
android:label="#string/app_name" android:screenOrientation="portrait"
android:launchMode="singleTop">
<intent-filter>
<action android:name="com.xyz.android.intent.action.BROWSE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".activity.TvbTabActivity" android:configChanges="locale|orientation"
android:screenOrientation="portrait" android:launchMode="singleTask">
</activity>
You can't. Android will try to restore the app where it left off. The correct way to handle this is to ensure that you understand the Activity life-cycle and put the appropriate initialization in the appropriate place.
There are a couple of ways to solve your issue, the best would be to check the Android Life-cycle diagram http://code.google.com/android/images/activity_lifecycle.png and try to figure out a way to make the app work within that context.
Of course if you really want to you can kill your own app by calling Activity.finish() when it hits the onPause() or onStop() states, but that is quite an ugly solution.
You can't do anything about this -- what is happening to you is what the force stop API does and is intended to do.
Task killers are abusing that API.
They can no longer use it in 2.2 and later.
If you really want to avoid it, you could limit your app to only 2.2 or later. Or if the problem is users are complaining about them, tell them to stop using task killers. Or if the problem is just that you don't like this happening when you use a task killer, then don't use a task killer.
Also this is the same behavior that happens when the user presses "Force stop" in the manage application's UI. That is generally fine though since the user must explicitly do that, instead of what these task killer apps have been increasingly doing where they just whack stuff in the background without the user being directly involved.

Categories

Resources