I have on dialog activity with 2 buttons which is being display when native caller id screen displays. Two buttons are click-able and also I can pick up and reject call by android native screen buttons.
Problem is when this dialog displays, animation of native call screen stops. I have seen this things in Truecaller app and also Current Caller Id app. I have also used following some codes
Manifest.xml
android:launchMode="singleInstance"
android:taskAffinity=""
android:theme="#android:style/Theme.Dialog"
android:windowAnimationStyle="#android:style/Animation.Translucent"
android:windowBackground="#android:color/transparent"
android:windowIsTranslucent="true"
And activity.java
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
getWindow().setFlags(LayoutParams.FLAG_NOT_FOCUSABLE,
LayoutParams.FLAG_NOT_FOCUSABLE);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
requestWindowFeature(Window.FEATURE_NO_TITLE);
and adding flags from intent call
Intent i1 = new Intent(this, activity.class);
i1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i1.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
i1.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
i1.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
i1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
I have tried lots of things to achieve this, How can I create dialog so caller id animation don't stop. Thanks in advance.
I implemented a solution that works well for me (and does not stop animation), here it is: https://github.com/inez/CustomIncomingCallScreen
Related
I want to launch an activity from another application inside my own app. I have control over both applications.
For it, I'm using the explicit intent and it works well.
Intent intent = new Intent();
ComponentName componentName = new ComponentName("br.com.example.app","br.com.exemple.app.myactivity");
intent.setComponent(componentName);
My problem occurs when I click on the overview button, the new application appears inside the same item when overview screen (Recents Screen). Thus, the user can figure out if he is one the App1 or App2. Actually, he will think that he is still inside App1.
How do I force it to appear on a different item on the Overview Screen?
I already tried to use
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
and
<activity
android:name=".myactivity"
android:exported="true"
android:screenOrientation="portrait"
android:theme="#style/ApiBaseThemeNoActionBar"
android:documentLaunchMode="always">
</activity>
It seems to work well when using only startActivity(intent).
See the documentation for FLAG_ACTIVITY_NEW_TASK:
This flag can not be used when the caller is requesting a result from the activity being launched.
So in your case, I guess if you're asking for a result, android forces you to stay in the same task.
I manage some events in a background BroadcastReceiver. In some specific situations I need to launch an activity. This activity is supposed to be hidden. Nothing should be displayed to the user.
It works well but if the user is using the keyboard, typing something, the keyboard is hidden. If the user is using GMail, writing an email, then a "draft" is saved.
It seems like this activity gets to the top and stops the one the user is using even if it is invisible. Is there any way to solve this?
This how I declare the activity in manifest:
<activity
android:name=".MyInvisbleActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar">
</activity>
This is how I launch it:
Intent intent = new Intent(MyContext, MyInvisbleActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MyContext.startActivity(intent);
This is the MyInvisbleActivity onCreate():
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//setContentView(---); //This is not used
Window oWindow = getWindow();
oWindow.addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
--do work--
}
Thank you!
Android provides a theme for this android:theme="#android:style/Theme.NoDisplay"
Alternatively it sounds like you might actually want a service. But youd need to provide more information on what you are trying to achieve
For an App I am developing, I override the back button to make it act like the home button so that the state of the main activity is preserved even when the app is exited. Now, I also send a notification to the user from time to time using a service. When this notification is pressed I want to open the main activity again. I noticed though that this creates a second instance of the app, which creates major problems. I am trying to make the main activity go to the front again, without calling oncreate again like so:
Intent to launch main activity again:
Intent notificationIntent = new Intent(this, MainActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
This doesn't work though. I still end up with two instances of my main activity. Does anybody know how to fix this?
By the way, I already have android:launchMode="singleInstance" in my manifest.
There's a way to force the OS to create only one instance of an activity and thats using the tag launchMode in the Manifest as shown below:
<activity android:name="YourActivity"
android:launchMode="singleInstance"/>
Hope this Helps...
Regards
Try adding this flag to the intent .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP), works for me.
I've searched and searched and searched for this!
So I've got an app widget and it has a configuration activity that I can open when pressing a button on the app. The scenario is:
Had the app opened.
Closed the app with the home button.
Selected to add my widget
I have configured the widget.
Placed on my home screen
Then open the configuration activity again with the button on the widget.
Cancel the new config by pressing back will put me back into the app.
When pressing back I want to just return home.
Basically what I'm asking is. How do I start the configuration activity in it's own task/stack?
I've looked into intent filters but I'm just not quite sure, or maybe it's something to do with the package it's in, or maybe it's just not possible!
I suppose it may have something to do with the intent I use to launch the config activity
Intent configIntent = new Intent(this, Configuration.class);
configIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
remoteView.setOnClickPendingIntent(R.id.config, PendingIntent.getActivity(this, 0, configIntent, PendingIntent.FLAG_UPDATE_CURRENT));
Perhaps because I launch it with 'this' as the context, it will always start in my applications stack...
but the pending intent api is:
PendingIntent API 1
"Note that the activity will be started outside of the context of an existing activity"
So yeah I'll stop talking now as I just end up going in circles!
EDIT
So tried android:launchMode="singleInstance" in the manifest like was stated. This worked however it stops the 'startActivityForResult' behaviour working correctly. (which is the whole reason for a config activity) Get the error:
WARN/ActivityManager(59): Activity is launching as a new task, so cancelling activity result.
So still haven't found a solution.
Ok sorted it :-) needed:
android:taskAffinity=""
in the manifest, setting the task affinity to an empty string allows for the activity to start in it's own stack, as it is not 'affiliated' with the rest of the application.
UPDATE
I have changed the task affinity to:
android:taskAffinity="com.my.package.alternative.task"
as each time I launched the activity it was showing up multiple times in the 'history'. So it now starts in it's own stack but is shared with other instances of the same activity.
Also need to add the Flag Intent.FLAG_ACTIVITY_NO_HISTORY to your intent :-) this stops your getting your application multiple time's in the history when you 'press and hold' the home button.
UPDATE
I've noticed FLAG_ACTIVITY_NO_HISTORY wasn't doing what I wanted, I've removed it and added:
android:excludeFromRecents="true"
into the activity tag in the manifest as well. The activity now behaves like I want :-)
Got this answer from the following link trail:
Tasks & Back Stack |
Managing Tasks |
Affiliation Tag
Try to put android:launchMode="singleInstance" for an activity of the app in AndroidManifest.xml
I was wondering if anyone can tell if how to pop a dialog screen up over a native Android screen?
I currently have an application that traps an outgoing call and stops it, I then want to pop up a dialog that would take over from the dialler screen and alert the user that there attempt to call has been blocked and allow them have some new options from the dialog.
I know that some people will say that I should use notifications instead but I'm aware of that and its not the way that it should work, I need to be able to pop up a dialog when the call gets trapped.
This is my dialog code so far
AlertDialog LDialog = new AlertDialog.Builder(context)
.setTitle("Call Blocked")
.setMessage("Call Blocked, reroute call?")
.setPositiveButton("ok", null).create();
LDialog.show();
I presume I have to somehow get the context to be that of the dialler screen?
Can anyone offer any help and assistance or links to tutorials?
Thanks in advance
For my application I used an activity with the Dialog theme.
You can declare the theme in the manifest file :
<activity android:name="PopupActivity"
android:launchMode="singleInstance" android:excludeFromRecents="true"
android:taskAffinity="" android:theme="#android:style/Theme.Dialog" />
use launcheMode="singleInstance" and taskAffinity="" if your popup is detached from your main application. Otherwise user may click the back button and return to the previous activity of your application.
excludeFromRecents="true" to avoid your popup to appear in recent tasks (long press home)
theme="#android:style/Theme.Dialog" to set the Dialog theme.
How to get the equivalent of launchMode = singleTask in code
I have not seen a clear explanation of how to set these flags programmatically, so I will include my results here. tldr: you have to set FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_MULTIPLE_TASK.
If you launch this directly from your app, your dialog will appear on top of your app's last Activity. But if you use a PendingIntent broadcast by AlarmManager to launch your "dialog", you have time to switch to a different app so you can see that your "dialog" will appear over that other app, if the style is set appropriately to show what is behind it.
Obviously one should be responsible about when it is appropriate to display a dialog on top of other apps.
public class MyReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// you have to set these flags here where you receive the broadcast
// NOT in the code where you created your pendingIntent
Intent scheduledIntent = new Intent(context, AlertAlarmActivity.class);
scheduledIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
scheduledIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
context.startActivity(scheduledIntent);