How can i add certain flags to my Intent.ACTION_CALL? - android

i built an activity that can launch itself when i hit a certain button-combination on my locked screen. I also managed to keep the activity running despite pressing the powerButton two times --> screen off and screen on --> activity is still running and keyguard still retired from duty. This is done by adding flags in the onCreate()-method of my activity.
i.e. getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
Now i want to achieve the same with the Intent.ACTION_CALL. But the problem is that i can't override any method of that intent as it seems to be exclusively run by android. Also, adding flags to the intent before i hit startActivity doesn't work as i can't use the necessary flags here.
Does anyone have an idea how i can achieve it?

If I understood correct, you want to make another activity, you starting with Intent.ACTION_CALL action, to add some flags to it's window.
It's not possible on Android. It means another app should give everyone rights to control itself in order to do this.
You can only add flags to Intent for controlling new activity start and tasking options.
See official documentation, you can use flags, that starts with FLAG_ACTIVITY

Related

Start an activity from any other app

I'm designing an app composed two activities. The first one always run, and is asked to trigger a second one when some stuff happens. This works fine with the standard code used for running activities:
Intent myIntent = new Intent(this, allarme.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(myIntent);
however, the activity in allarme.class is not started if i'm using another app (i.e. gmail),
whilel it works perfectly from home or when the screen is locked.
I'm sure that the first activity is still running, it's just that the second action is not triggered.
Should I change anything in the manifest file to fix this?
I'm not really clear about what you want.
but I guess you want to run two activities simultaneously, am I right?
while one activity run in background and one activity update the UI.
always keep in mind that Android architecture only allowed one activity to run at the time. If you want to pass the data from Asynchronous Task, you can call the method from that class and let your handler 'recent' class update the UI.
You can create a background service that always run at background even if you are using another app or phone is locked. Here is link for more help :
http://developer.android.com/training/run-background-service/create-service.html
Thanks everybody, I think I solved it.
Basically, I found out that an activity already running can be brought to focus when re-started with a basic startActivity. Then I can immediatley switch to the new activity without losing the focus.

Saving State With Android

I have an app that will never require more than one instance of an activity. I want it so that when the user comes back to a screen it is in the same state as they left it except for a few places where it doesn't make sense. I've worked out saving the persisted data with onpause onstop updates. However to keep the screen looking the way it did when they left it i use intents specifically setting the flags to Intent.FLAG_ACTIVITY_REORDER_TO_FRONT|Intent.FLAG_ACTIVITY_SINGLE_TOP then startActivity. It seems to work great but does it make sense? Is there a smarter way? Pitfalls doing it this way etc... any feedback will be greatly appreciated.
android:launchMode = "singleTask"
add the above line for every activity in the manifeast file. Adding these launch relaunch the activity instead of creating the activity again.
Refer this link

android sdk. startActivity() moves prog. to background

I'm simply trying to change between xml files/layouts.
In my main activity I have startActivityForResult(new Intent(this,playlist.class), 0);
I've added the class to my manifest, created the class where the package is com.site.mainactivity, and superclass is android.app.Activity.
I didn't "extends playlist" in my main activity
My logcat only shows "showStatusIcon on inactive InputConnection", "InputConnection = android.view.imputmethod.BaseInputConnection#40532b90, active client = false"
When I try to start the new activity/switch layout, my home screen shows, but my app is still running in the background. When I go back to it, the app takes me back to the main screen.
What am I doing wrong?
Thanks
This sounds like a problem with how the Activity stack is being maintained. Specifically this is because based on the Manifest properties, an Activity can have different properties that specify how the Activity should be treated by the manifest ie. if it is included in the Activity stack or not and/or Also this could include where the main entrance of the application is, and whether or not an external intent can go to a specific screen in the application.
With manipulation of this it is easy to control. Look up the ActivityManager and how tasks are retrieved and maintained and analyze the design flow of your application. You must fully understand how you want it to work to fully solve your problem. A flow chart would aid you in this diagnosis.
Learn to control your flow properly.
If you just want to change the layout, you can either:
call setContentView again
use singleTop and launch the same activity but with a different layout
close the first Activity with finish() after launching the second
What I did to bypass this hurdle was simply use getLayoutInflater().inflate(R.layout.main, null); as a View and then setContentView(v)
I just need to reinitialize events, views, etc so that the program runs as it did before it changed the view.

I need to use "singleInstance" in main activity, and also i need bring another activity to the top

I need only one instance of my app, so I use android:launchMode="singleInstance" in main activity section in manifest, but this causes: when I click on home button when second activity is displayed and launch my app again, main activity is displayed, but I need to display second activity (I need standard behaviour). Problem is caused by using singleInstance in activity's manifest so this activity is always on top. I tried to launch second activity with various flags, but this doesn't work. (android:launchMode="singleTask" doesn't work too).
singleInstance and singleTask are only needed in very rare cases.
You probably don't need any special launch mode to get the behaviour you want. Just try the standard launch mode and see what happens. In most cases you don't need any special launch mode unless your application is started by other applications and you want to be able to control that.
If you try the standard launch mode and have problems, please indicate what the problem is in more detail and we can probably help you.

How to hande each Intent once when using singleTask

I'm using a singleTask-mode activity that handles a certain type of files by specifying a intent-filters.
I need to handle each such file Intent exactly once. The problem is onNewIntent() is only called if the task is already alive, forcing me to handle the intent from onCreate() too. Unfortunately, onCreate() gets called for a whole bunch of reasons (e.g. screen rotation), and the Intent returned by getIntent() may be the same one across several onCreate()'s.
Of course, it is possible to work-around this using some ugly hack, but I was wondering what the elegant solution would be.
So far the best solution I came up with is to setIntent(new Intent(Intent.ACTION_MAIN)) every time after handling an intent. This is a similar pattern to how web servers redirect you to a GET page after a POST page to avoid redoing an operation as result of refresh.
Thanks!
I am not sure If I get your Problem, but once you call an intent and start the new activity,
immediately after call finish(); to end the activity you are leaving. This will end your last activity and will prevent from multiple activities from running at the same time.
Also if you are using screen rotation as a way to launch activities, you can always control which one's you do not want to start multiple times by setting some checks using "If and Else" Statements.
remove singleTask will solve your problem;
call remove singleTask's activity, can replace with:
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
How about setIntent(null) after handling it?

Categories

Resources