Every activity shows its own icon - android-activity

I have a few activities in my app, but for some reason on the menu there are a lot of
Icons of my app- for every activity.
How can I fix it and make an Icon for MainActivity only?
Ty.

In your manifest remove these lines from all Activities except the one you want to open on:
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
(I recommend removing them from all the activities exept MainActivity).

Related

Alarm Activity gets launched on launching the app

Scenario : I have a simple to-do app where In the main activity I have a fragment that takes a list of to-dos from the user. I set an alarm for a fixed time in the future (in my case every 2 min ONLY for testing. The AlarmReceiver class launches an AlarmActivity which shows the list of to-dos as checkboxes for the user to mark as done.
When the alarm comes up and shows the list, I have a "Submit" button to mark all the checked items as 'done' in the local db.
Problem:
This AlarmActivity disappears on click of submit since I'm calling finish on it. But when I launch the app from the icon, the AlarmActivity is shown instead of the main activity.
AlarmReceiver code :
final Intent intent1 = new Intent(context, CheckListAlarmActivity.class);
intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_NO_HISTORY);
context.startActivity(intent1);
AndroidManifest.xml
<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=".MainActivity"
android:noHistory="true"
android:clearTaskOnLaunch="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AlarmActivity"
android:alwaysRetainTaskState="false"
android:clearTaskOnLaunch="true"
android:showOnLockScreen="true"
android:screenOrientation="sensorPortrait"
android:noHistory="true"/>
<receiver android:name=".AlarmReceiver" />
</application>
I added the android:clearTaskOnLaunch="true" and that seems to do the trick sometimes but not always.
And in the background when I put the loggers, it shows that every time I launch using the app icon it calls the onCreate of the MainActivity and then immediately calls the onCreate of the AlarmActivity.
I have tried looking for all kinds of solutions and tried setting a bunch of flags to the Intent. Nothing seems to do the trick convincingly.
It seems like a simple problem but I am not able to find the solution. Any help/guidance would be appreciated.

Android cannot set screenOrientation,

I have read through every post I could find on this and other sites and followed the advice, but in the most simple implementation I cannot get the Note 5 to set to Portrait mode when it is physically in Landscape orientation.
I added the lines as recommended to the manifest file, rebuilt and the app starts in Landscape mode.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.twistlogic.miwidget">
<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:label="#string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I also tried doing this with code, which is my main purpose:
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
nothing is produced that works.
I am trying to learn Android so I understand this may well be due to my limited knowledge. What I am trying to do is fix the orientation and lock it there, then allow it to change only when the user pushes a button. I did read that the screen size had to be set after API 13. But I am not certain how to do so. I am using a fragment template screen from the basic activities when the project was created.
Thanks for any help.
This can be set in the Main Activity I have not tried to set it in the Manifest here is a single line of code and a few lines to write a test Ok here is the Manifest code at the end
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
int orientation = getResources().getConfiguration().orientation;
if(orientation == Configuration.ORIENTATION_PORTRAIT){
}else if(orientation == Configuration.ORIENTATION_LANDSCAPE){}
In your manifest file after your main activity Paste below line.
android:screenOrientation="portrait"
I have not tested this code in a Manifest file

How can I change starting activity in Basic4Android?

Is there a way to change starting activity in Basic4Android?
Always Main activity automatic added and set the starting activity.
Program not let to change its name too...
Is it possible?
Go to: "Project" -> "Manifest Editor" and a popup window with Android manifest xml code will show up. Insert this code after AddManifestText(... and change yourActivityName to what you want.
<activity android:name=".yourActivityName" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You can run Activity.Title= "YourTitle" in any activity to display alternative name in the title bar if that is why you are looking to change the startup activity.
There is no way, I think it is not possible.
You can switch names of two activities in the manifest editor which would effectively start your app from activity2 code module:
SetActivityAttribute(Main, android:name, ".activity2")
SetActivityAttribute(Activity2, android:name, ".main")

Getting Main Activity from Main Application

I have the following manifest.
<application
android:name=".MyMainApplication"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MyMainActivity"
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>
I also have the following global static function.
MyMainApplication application = MyMainApplication.instance();as technique described in Using Application context everywhere?
I was wondering, out from application variable, is it possible for me to get MyMainActivity?
There is no way to retrieve the application's main Activity using the Application instance.
Usually there is no reason to do this... perhaps there is a better solution than manipulating the main Activity directly as you apparently are doing. Maybe you should update your post explaining specifically what you are attempting to do.
You can start the activity form the MyMainApplication class though it doesn't extends Activity
In Main Application Class create new Intent and set the intent flags to Intent.FLAG_ACTIVITY_NEW_TASK . Activity gets instantiated. I have tested and verified.
code snippet for reference :
Intent intent = new Intent(this,MyMainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

How to fix screen orientation to portrait for my whole PhoneGap app

How to configure the Phonegap app to be fixed to only portrait mode, I there any possibility to do it with CSS or JavaScript so that I should be able to get the consistent behaviour across the platforms
I found this useful post detecting-displays-orientation-change-on-mobile-devices-with-accelerometer-a-platform-indipendent-approach
Here it is explained how to detect the orientation, but I need to configure it
Is it possible through CSS3 Media queries?
To fix your orientation in portrait mode just add the below line in your activity tag in AndroidManifest.xml file:
android:screenOrientation="portrait"
or this in the activity class:
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Actually you can use config.xml to set it to all devices if you're using PhoneGap Build...
Set the propertie: orientation with possible values default, landscape, or portrait
example:
< preference name="orientation" value="landscape" />
*please note that default means both landscape and portrait are enabled.
Source:
https://build.phonegap.com/docs/config-xml
use this code in your manifest
<activity android:name=".DroidGap"
android:label="#string/app_name"
android:screenOrientation="landscape" >
I had to update <path to phonegap app>/platform/android/AndroidManifest.xml with android:screenOrientation="portrait". Set to default, landscape, or portrait.
See below for a full example:
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="#string/app_name" android:name="HelloWorld" android:screenOrientation="portrait" android:theme="#android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>