Is it possible to show pop up dialog (AlertDialog) in home screen on the android device via services?
You could create an Activity with the Theme.Dialog theme. In your AndroidManifest.xml file add the theme to the activity, like this:
<activity android:name=".DialogActivity" android:theme="#android:style/Theme.Dialog"></activity>
From your service simply start this Activity. You will have to start the activity with the Intent.FLAG_ACTIVITY_NEW_TASK flag. See How to start an Activity from a Service
Does anyone needs option, "android:launchMode="singleInstance", when pop activity in the broadcast receiver or Service??
Without this option, my app started automatically and pop MyDialogActivity above it.
And then, something happened wrong. (My app has the Main Activity with auto-login function. When the other new Activity started automatically, MyDialogActivity is hided by it.)
So, this is my sample xml code.
<activity
android:name=".MyDialogActivity"
android:launchMode="singleInstance"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Dialog" />
<activity
I hope someone needs my comments. :)
You can not create dialog from service but we have one alternative solution is that You can create dialog activity and start that activity from your service
You can set Theme of activity as dialog by below way
<activity android:name=".MyDialogActivity" android:theme="#android:style/Theme.Dialog"
android:label="#string/app_name">
</activity>
Create CustomDialog As Activity
add to manifest
<activity android:name=".view.activity.CustomDialog"
android:launchMode="singleInstance"
android:screenOrientation="fullSensor"
android:theme="#style/AlertDialogTheme"
/>
add Style AlertDialogTheme to style.xml
<style name="AlertDialogTheme" parent="Theme.MaterialComponents.Light.Dialog.Alert.Bridge">
</style>
Related
I have one app with two activities A & B, both with launch mode singleInstance. I notice that even if both A and B are running in the background, only the last activity is shown in recent-apps list. Is it possible to keep both A & B in the recent-apps list? Thanks.
In the AndroidManifest, make sure to set the android:taskAffinity attribute of the element differently for each Activity. For example:
<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>
The trick is to start the new Activity via an Intent with FLAG_ACTIVITY_NEW_TASK flag enabled.
Each time my app icon from home screen is clicked, I want the app to start my FirstActivity.java. The problem now is, say I have navigated through my app and is in the ThirdActivity.java and I have clicked the home Button and go to check out my other apps. Again when I click the app icon in home screen, my Application starts from ThirdActivity.java. I want it to start from FirstActivity.java.
I have used clearTaskOnLaunch="true" in manifest for my FirstActivity.java and also checked using android:finishOnTaskLaunch ="true" in all my other activities but the problem is still there. How can I solve this?
All I have to do was declare android:launchMode="singleTask" in manifest for my FirstActivity.java "only". By doing this, every time user selects the app by clicking the app icon in the home screen, app will start with FirstActivity.java
Say the user has navigated through my app and is in the ThirdActivity.java and clicked the home Button. The user has the option of selecting the app again from the background apps section (task manager section). If he/she does so, it will start from where he/she has left (ThirdActivity.java). Only if they click the app icon will the app start from FirstActivity.java
you need to finish you current activity at the time when you are launching intent for new activity, there is a method to do that finish();
In your oncreate you just have to start your activity using Intent
In manifest you have to provide name attribute to application tag
<application
android:allowBackup="true"
android:icon="#drawable/app_logo"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name=".class name which extends Application"
>
Here you can see details on how to use application class:
http://www.intertech.com/Blog/androids-application-class/
http://developer.android.com/reference/android/app/Application.html
http://androidexample.com/Global_Variable_Or_Application_Context_Variable_-_Android_Example/index.php?view=article_discription&aid=114&aaid=136
You can use this code in onPause() of the second third activity but you have to take care of if onPause() is called because of clicking home button or by any other mean, Code is:
Intent intent = new Intent(AnyActivity.this,FirstActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
finish();
You can use moveTaskToBack(true) when you click on the homebutton and start the activity you want to.
I had resolved the issue by adding all three tags android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:finishOnTaskLaunch ="true"
in manifest splash screen activity may be helped some one:
<activity
android:name=".SplashscreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:finishOnTaskLaunch ="true"
android:screenOrientation="portrait"
android:theme="#style/AppThemeForAppCompact">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I'm trying to change the start up activity.
I created an activity when the app loads but I want to add a screen before that, I'm not sure where to change the Android manifest to load a certain layout/activity when the app starts.
The startup activity [Launcher Activity] is declared in the projects' AndroidManifest.xml file
Look for that activity tag in the manifest which looks like this
<activity android:name=".Main"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Look at the attribute android:name. Main is the class which is launched when the app starts. Currently your calendar activity name should be there. Change that to the .classpath of your activity that you want to launch.
That should do it. You may also want to do the hello world application in the tutorials and go through the docs a little to see how Android Applications work.
From here
Just create another activity and set it as Launcher Activity and after a timer (if that's your achieve) just call the other activity!
I am developing an android application. If I close my application, my app available in the "Recent Apps" List. Now I don't want to show it in "Recent Apps". How can I remove it from "Recent Apps List" after closing my application programmatically. Please can you share your suggestions.
In you Manifest.xml, set the following to your Root Activity
<activity
android:name=".Your_Root_Activity_Name"
android:excludeFromRecents="true"
....
</activity>
Depending on the results, you might also have to use the android:noHistory="true" attribute. But not sure if it is required in your case.
For more information about this: http://developer.android.com/guide/topics/manifest/activity-element.html
Add excludeFromRecents="true" to your activity in AndroidManifest.xml:
<activity android:name=".MainActivity"
android:excludeFromRecents="true" ...
override the onResume methods in your other Activities and there destroy them and call the main Activity.
In your AndroidManifest.xml, use this for Activity:
<activity
android:name="Your Activity"
android:excludeFromRecents="true"
android:noHistory="true"
android:taskAffinity="">
</activity>
Hi I have a Broadcast receiver with following code.
1. Intent i = new Intent(context, A.class);
2. i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3. context.startActivity(i);
This works fine and my activity does start, but it starts on top of my main activity i.e. B. What I want is that from my broadcast receiver I should be able start an Activity A, such that it does not start on top of B. Why B is always starting in background. What I am doing wrong.
Also, to mention by activity A has Theme.Dialog.
Please let me know your thoughts.
A new activity is supposed to start on top of existing activities.
If you want to start something without appearing in the activity history stack, maybe this something shouldn't be an Activity but a Service instead?
Edit: I think you can change this behaviour with FLAG_ACTIVITY_NEW_TASK in conjunction with android:launchMode="singleTask" in the Manifest. (see documentation on launch mode)
If you start an Activity then of course it will come foreground.The activity previously was in foreground will go to the background automatically.
If you don't need to start it on top of B,what about to start it from service?.Let Activity A stay as it is.
If you need to access anything from service and no need to show the activity,then surely you are looking for other then starting an Activity with an intent.
Finally if you really want to start Activity A,and B will be on top then start Activity B after starting A
I think you mean you want to start the application with a different activity. You can edit your AndroidManifest.xml file to make a different activity start first.
EDIT: Heres an example:
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".MainActivity" <-this will start first
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 =".otherActivity"
android:theme="#android:style/Theme.Dialog">
</activity>
<activity android:name=".anotherActivity"></activity>
</application>