Well, just like the title suggests, every activity within my application is being added to the app drawer.... Im really hating this new ADT. First it was a problem with the app name appearing as the first activity name, now all the activities are showing up on the application list. If I go to uninstall it only shows 1. Anyone else having this problem and has figured out a work around?
for future cases specifically you can change in the android manifest under :
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
change to:
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
This will remove the activities' icon from the app drawer. As the OP says: sometimes the wizard puts this in the manifest for you.
Ok, figured it out... Everytime you create a new activity through the adt wizard (New -> Android Activity) it creates the code in your manifest for you.... the problem is that it added intent filters to it as well. Just remove those and they dont show up.... stupid adt.
I know when I am using IntelliJ as my IDE for Android programming, there is a box you can check when using the wizard to create a new Activity that says "Mark as start-up Activity".
Be aware of these types of things because that is what caused me to have the same problem you had Shaun.
I wouldn't completely erase the intent filters, simply have only the Activity you want as the "start-up" Activity marked as the "Launcher" in the Manifest file. All other Activities get "Default".
Related
Hello my question is a bit difficult let me explain and try to understood
I have a custom Home who is set as default when user press home. Know i need a way to ask wich home use when i press on a setting key, or a way to launch Setting activity for delete home default action.
In fact i wan't a way to go back to home app installed by google instead of mine just in case.
I need this because my custom home is still in dev and don't have all feature yet.
I need to keep my home as a default action when user press home buton but i need to add a home selector in special case.
I have try to use finish() when i need to go back to old home but mine as default is automaticly relaunch because he is the default one.
Any idea?
EDIT
I try to reformul a bit.
I'm making a home apps. I set it as default on my tablet. My home apps don't have all feature yet. And when i will launch something or go to setting i need to relaunch default home app.
So i need a way inside my app to reset default home action or launch a home apps, or ask user to choice wich app he will use has home apps.
Hope this is clear for all.
Probably you should use this one to implement your idea. keep the below lines in your manifest file.
<activity android:name="Home"
android:theme="#style/Theme"
android:launchMode="singleInstance"
android:stateNotNeeded="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
For more info about the sample project. just go the below path in your Android SDK
\android-sdk\samples\android-8\Home
EDIT :
Hi Please check this to pro grammatically unset the default application.
How do I use PackageManager.addPreferredActivity()?
for more info go through this also to clear the clearPackagePreferredActivities
http://developer.android.com/reference/android/content/pm/PackageManager.html#clearPackagePreferredActivities%28java.lang.String%29
hope this helps you.
I'm in the process of trying to make a release build of my first android app to send to a few testers. However, I ran into a problem with it. When you exit the app and then re-enter it by launching it via its icon, it restarts the whole app instead of returning to it's previous location. This occurs even if you re-enter right after exiting. However, it does not happen if I hold the Home button and launch it through the recent apps list.
I've searched online for others having this problem and there are a few, but no one has ever had a solid answer as to why it's happening to them. It's been suggested in old questions to set the launchmode to singletask or singleinstance in the manifest file, but that hasn't helped me, and besides - from what I understand, the default behavior for android is to return to the previous state of the task in this situation, so I don't know why I would need special manifest options to make it do that.
The most bizarre thing about this problem is that if I use eclipse and the debugger to put the app on my phone, this problem does not occur. I don't even need to be connected to the debugger, it seems like as long as I have a debug version of the app, the problem doesn't occur. But if I use a release version (I create it using the Android Tools - Export Signed Application Package menu option in Eclipse), the problem happens.
If anyone has any insight as to what is causing this, I'd love to hear your thoughts.
I had the same problem with an application and I resolved this behavior adding flag "android:launchMode="singleTop"" instead of "android:launchMode="singleTask"" in the <activity> declaration of your AndroidManifest.xml file. Hope this will help somebody.
So far I've found out that it's an issue based on how you install it in your real device, specifically:
If you simply copy and paste the APK to your device's local storage and install it from the device, regardless of whether it's signed or unsigned or taken from bin folder, it shows this behavior, app restarts from menu icon.
If you install it using one of the following options, This issue does not appear:
Go to sdk/tools/ using a terminal or command prompt then type
adb install <FILE PATH OF .APK FILE>
In Linux, type:
./adb install <FILE PATH OF .APK FILE>
Simply run your project from Eclipse.
I would be pleased to know if there's any possible way to distribute correct APKs for beta testing. I already tried exporting a signed APK because when you copy and paste an APK and install it manually it shows the rogue behavior.
Update:
I found out a solution. Follow these two Steps:
Set android:launchMode="singleTask" = true for all activities of your app in the AndroidMainifest.xml inside the activity tag.
Put this code in your Launcher Activity's onCreate().
if (!isTaskRoot())
{
final Intent intent = getIntent();
final String intentAction = intent.getAction();
if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null && intentAction.equals(Intent.ACTION_MAIN)) {
finish();
return;
}
}
This behavior is a bug in Android. Not a special case.
// To prevent launching another instance of app on clicking app icon
if (!isTaskRoot()
&& getIntent().hasCategory(Intent.CATEGORY_LAUNCHER)
&& getIntent().getAction() != null
&& getIntent().getAction().equals(Intent.ACTION_MAIN)) {
finish();
return;
}
write the above code in your launcher activity before calling setContentView. This will solve the problem
You could use launchMode as singleTop to the Launcher Activity in AndroidManifest.xml
<activity
android:name="<YOUR_ACTIVITY>"
android:label="#string/app_name"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
It is the default behavior in Android. For the debug builds it works differently for some reason. It can be solved by adding android:launchMode="singleInstance" to the activity, you want to restart after you launch from the icon.
Add this to your first activity:
if (!isTaskRoot()) {
finish();
return;
}
super.onCreate(savedInstanceState);
Try using android:alwaysRetainTaskState as shown in the following example:
<activity
android:name="com.jsnider.timelineplanner.MainActivity"
android:alwaysRetainTaskState="true"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
For me, I found that I had erroneously posted NoHistory = true in my activity attribute
[Activity(NoHistory = true, ScreenOrientation = ScreenOrientation.Landscape)]
This prevented the app resuming into this activity and restarted
You can try to set android:alwaysRetainTaskState="true" for your launcher activity in AndroidManifest.xml.
<activity
android:name=".YourMainActivity"
android:alwaysRetainTaskState="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
For details you can see https://developer.android.com/guide/topics/manifest/activity-element.html#always
I see this issue on Android TV in 2019. Is there a better fix for it? other than
if (!isTaskRoot()) {
finish();
}
It works but looks like a hack more than the actual solution.
All of the solutions above didn't work consistently on all of my devices. It worked on some Samsung but not all.
The cause of the problem for me was installing the APK manually.
For me the fix was adding LaunchMode = LaunchMode.SingleTop to my Activity attribute over the Main Activity:
/// <summary>
/// The main activity of the application.
/// </summary>
[Activity(Label = "SilhuettePhone",
Icon = "#drawable/icon",
Theme = "#style/MainTheme",
MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
ScreenOrientation = ScreenOrientation.Portrait,
LaunchMode = LaunchMode.SingleTop,
WindowSoftInputMode = SoftInput.AdjustResize)]
I had a problem with a restarting app, my problem was in themes:
I have differents fragments and I would have one background for all. But this cause a restarting app in some devices(.
I've deleted this line in themes and this helped:
item name ="android:windowBackground">#drawable/background /item
Removing task affinity rather than launch mode has worked somewhat for as it has its own demerits
When you press the back button in Android, the onDestroy method is invoked (as opposed to pressing the home button, where only the onPause() method is invoked).
If you need your app to continue where it left off, save the state of the app in your onDestroy() method and load that state in the onCreate() method.
I am creating an app using Wikitude API, but I haven't been able to customize the view.
I have asked the developers and I know I can't add buttons to the main view in the current release version (for Android), but I am wondering if I can add more buttons to the options menu. Right now when I press it I get just one button that says "Ignore Altitude" can I modify that button and/or add more buttons to that menu?
I have checked other posts but there aren't any answers. The posts are a little bit old so that is why I am asking again.
I haven't found any useful documentation.
Any help is greatly appreciated
if I understood your question correctly, then please try the following: in the method prepareIntent() of your main Activity, you can add up to 3 menu items:
intent.setMenuItem1("Menu 1", YourActivity.CALLBACK_INTENT);
intent.setMenuItem2("Menu 2", YourActivity.ANOTHERCALLBACK_INTENT);
Then you define the callback function as another activity (with dialog, list and stuffs). It works fine this way for me.
I am also playing around a bit with Wikitude, but hard to find something well documented!
Yes , You can Add upto three menu button as if you read doc properly
intent.setMenuItem1("Menu Name", YourActivity.LOCATION_INTENT);
intent.setMenuItem2("Menu Name", YourActivity.LOCATION_THREATS);
intent.setMenuItem3("Menu Name", YourActivity.MAP_INTENT);
With making Intent variable as
public static final String LOCATION_INTENT = "wikitudeapi.mylocationactivity";
Also declare action in manifest as,
<activity android:name=".activities.Your Activity Name"
android:theme="#*android:style/Theme.Translucent.NoTitleBar"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="wikitudeapi.mylocationactivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
The documentation says you can specify a custom category.
When, why and how would you do it?
What would be the use of it?
The way I understand it, categories are public directives to the android operating system(and other apps) that represent different categories that your app should be a part of.
Example
When the launcher icon is tapped on the home screen, the home application looks through every installed app's manifest for the HOME category -- and if so it displays it in the app drawer.
However, there's more. You can specify categories in your applications manifest that lets the system know that you application can handle the intent category. For example, by putting a ALTERNATIVE category, other apps in the system know that your app can handle that category without specifically knowing the action name! In the following example, custom intent categories are passed through this intent, which is filtered and the corresponding object gets edited(taken from the Notes example app):
<intent-filter android:label="#string/resolve_title">
<action android:name="com.android.notepad.action.EDIT_TITLE" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.ALTERNATIVE" />
<category android:name="android.intent.category.SELECTED_ALTERNATIVE" />
<data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
</intent-filter>
By registering this intent filter in an <activity /> tag, you can edit a "note". The intent data would contain the note, and the intent would get routed to the activity that this filter is registered in.
In Conclusion:
There isn't really a reason you'd use a custom category. They are for Android, and thus don't really make sense in application use. But, if you choose to use them, they can be used in the methods described above. "They provide some specific semantic rules, and if those rules are useful to you then feel free to use them"(Hackbod).
http://developer.android.com/guide/topics/intents/intents-filters.html
Scroll down a bit and you should see a section under "Intent Objects"
They basically describe certain special properties of an activity. for example, adding
<category android:name="android.intent.category.HOME" />
means that the app can be started on the phone's bootup
I'm kinda a noob to Android still, although I have programming experience otherwise.. It says a custom category in your own namespace. I'm guessing that if you are programming multiple apps and you want one app to run another app, you could use a custom category for your intent to force the phone to find your other app to catch the intent with?
When you do not want to use the default category then use the custom category.
Custom categories should use the package name as a prefix, to ensure that they are unique.
Some information is provided on below link:
http://developer.android.com/guide/topics/manifest/category-element.html
Check the below link it has somewhat same question:
Android custom categories
Can somebody please throw some light on the arcane error "Failed to
set top app changed", by the activity manager?
I'm wondering what causes this error. In one of my application I'm
making a view fullscreen and then switching back. For the first time
things are ok but then if i try to make the view full screen again, I
get a crash and the error mentioned above is found on logcat.
Any help is greatly appreciated.
Reagrds,
M
I just encountered this problem today myself.. let me tell you what did the trick for me... maybe it will help you too.
anyway in my case it crashed because i overrided onActivityResult and inside that event i tried to do this:
Bundle extra = data.getExtras();
String albumId = extra.getString("id");
this is old code that got left in the application.. after deleting this everything worked as expected.
hope this helps in some way.
I had the same problem with my app, the activity crashed and "activity manager: fail to set top app changed!" in logs. Turned out to be one line of code in the onPause caused the problem. Check your onPause method of the Activity that launches the new Activity to see if something should not be done there. I think there could be many reasons causing this problem, but the basic idea is that the launching activity does something wrong when the new Activity is going to show up.
My problem was that i change orientation on activity start and needed to add android:configChanges="orientation" , like this:
<application
android:icon="#drawable/icon"
android:label="#string/app_name" >
<activity
android:name=".RiskniMilionActivity"
android:label="#string/app_name"
android:configChanges="orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>