this might be an easy question but i have a notification that when clicked open up the stock messaging app
arg1.setClassName("com.android.mms","com.android.mms.ui.ConversationList");
but i noticed that every time it is clicked the activity keeps stacking up and i end up having to use the back button a bunch of times to get out of it. I have always used android:noHistory="true" in the manifest but obviously i cant do that here so is there a way to do the same thing with when the intent is launched?
Try using arg1.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY) before calling your intent, which might solve your problem...
You can use Intent.FLAG_ACTIVITY_REORDER_TO_FRONT. If the activity is already running, it'll be brought to the front.
Related
When using the intended(IntentMatcher) from the Android Espresso API, is it possible to do this twice in the same Activity?
So for example I click a button which starts an Activity for result. I check that this Activity has fired using intended(IntentMatcher). That works.
However, when I get the result, I want to fire off an Intent for a different Activity. In this case just a local Activity in the same app package with no result.
When I do this manually in the app it works fine, but Espresso can't seem to detect the second Intent in my test. What I am I missing or is this not possible? Alternatively, how should I be doing it? Maybe my design is bad.
When I do the check I'm trying this:
intended(toPackage(<packageName>));
intended(hasComponent(hasClassName(<className>)));
The first line matches but not the second one. And even if the second line is not completely correct it never seems to show anything in the error log about the second Activity I'm actually starting.
Another thing adding to the confusion is that two intents are definitely being fired as it shows that in the log. They both seem to be the same one but with slightly different details - one is a package, one is a component. Does it log the result from the first Intent as an Intent in itself? Sounds unlikely but where is this other intent coming from? I know it's not the second Activity I'm launching as it still fires even when that Activity isn't called (when the first Intent result is a fail).
I've also considered that maybe it's not getting detected because it's not waiting long enough for the second intent to fire. If that were the case, what would I do about that? I don't see much talk about handling time sensitive things in Espresso. Like checking if a progress bar is shown but then hidden again while not pressing anything. How do you do that? Maybe it's the same answer.
Any help appreciated!
Ok I found the problem. My IdlingResource wasn't working.
After fixing that it works like a charm :)
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.
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
I am pretty new to Android development .
My problem is a bit tricky one.
I want to develop an application using 2 activities.
1st activity has a button . On clicking the button I want activity 2 to get started as follows:
Activity 2 will come to foreground for 2 seconds and then goes to background for 8 seconds , after which it will again come to foreground for 2 seconds and then again goes to background and the process continues.
Meanwhile both activities should continue their respective tasks.
For ex. We can have a Activity such as Music player which is playing music and another activity named Activity 2 which is downloading some files.
I have tried many things ranging from using Intents to minimizing a activity and displaying notification on notification bar. The problem with notification bar is that it on resuming the activity using notification bar it is always calling OnCreate() method thus again starting the activity.
I am able to start a activity on button click but don't know how to minimize it and then pop it up in same state .
I am using services in background for timing delays .
Please Help and share your solutions to this problem.
I have solved the problem.
The solution is to modify manifest file as :
add to main activity code
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
add to child activity code
android:launchMode="singleInstance"
android:clearTaskOnLaunch="true"
Its works perfectly for my app :)
thank you all for your kind contribution
Maybe u found solution for this issue as u said, but in any case, I would recommend reading some things.. It will help you to better understand that:
There is no such a thing as minimizing activity (Activity Lifecycle),
Activity/Intent Flags and lunching modes
Tasks and back stack
What is service used for,
What are AsyncTasks,
How to use Handler
Oki.. I made some effort and organize links for you. I know it seems a lot of material, but you don't have to run to read them in next 15min.. Take it easy, read, try, learn. Take this as advice, cause once u get used to do things in a wrong way it will be much more difficult to correct them later..
Hope you find it useful.. ;) Cheers
moveTaskToBack(true); moves the whole task to back i.e. it moves both activities to back . Then the problem will be to move the activity to foreground which I don't know.
Have you tried using
this.moveTaskToBack(true);
I'm not sure if this is what your looking for or not. Heres the Documentation as well!
I'm looking to find out how to stop an activity instead of resuming upon the click of the item on the notification list. Any ideas?
Overload onNewIntent in your activity and when you get the intent from the pending intent just call finish()
Your activiy will need to be a singleInstance activity though. Otherwise, a new activity will get created on the task stack when the notification item is clicked.
Can you be more specific about what you're doing. Are you trying to write another Task-Killer-like application? or perhaps some kind of music player application? Telling us about the kind of application you're writing can help us help you.
By the way, using the term "resuming" shows that you haven't fully understood the Activity lifecycle yet. onResume is for resuming the UI thread. onRestart is the one that's used for restarting the Activity.