Android UI transition not as expected - android

I am trying to launch an SMS app (Messenger/Hangouts) from my app. But the UI transition is not as expected. On launch, my app moves to the background and SMS app is launched from below the screen and this transition is slow and very much visible to the user.
I want the transition to be as fast as possible without showing any animation. I tried overridePendingTransition(0,0) and setting the Intent flag (FLAG_ACTIVITY_NO_ANIMATION), still does not help.
What should I be doing to acheive this?

This snippet of code works fine for me:
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setData(Uri.parse("sms:"));
overridePendingTransition(0,0);
startActivity(sendIntent);
Please paste the relevant code you have used for the same if the above does not work and I can look into it. Hope this helps!

Related

Create new intent in background

I am looking for a way to launch another app from within my app but so that the focus is not changed from my app to the app launched.
I.e currently I have the new app launched via a intent, however when this is carried out the new app is launched and becomes the app in view, I need it to be kept in the background with my app still in view.
The reason for this?
I am developing an application for internal use that will act like a lock-screen to the device so although things must happen in the background the 'lock-screen' must always be on top.
I have done some research into intents and launching other apps but can not find anything about what I need.
Hope you can help thank you!
Currently the terminal is called like this:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("jackpal.androidterm", "jackpal.androidterm.RemoteInterface"));
intent.setAction("jackpal.androidterm.RUN_SCRIPT");
intent.putExtra("jackpal.androidterm.iInitialCommand", cmdString);
The reason it needs to be running in the background is so that the app can run commands in terminal without the user having access, but then they 'unlock' the screen they need to then be able to view the terminal and what commands are being run etc
You can not startActivity in Background.Instead start the activity and minimise the activity(in your case this activity is of different application) using moveTaskToBack(true);
In your case, put a condition based on your intent and its params and use moveTaskToBack(true); so that activity will be minimised only when your application launches.
This won't be possible, you will have to start a background Service that does the actual work and only launch the Activity you want to navigate to once your foreground Activity is finished. Depending on your architecture, you can store the Activity to call when your foreground Activity is finished and change it from the service. That way you will have your desire behaviour without having to actually call the Activity.
In addition to the answer from #Meher, in the intent for your current starting activity, you can add the flag FLAG_FROM_BACKGROUND.
With this you get rid of the "blinking" effect (the one where your activity shows for one fraction of second while it discovers wether to go to background)

Stay on my activity when dialing

I am using the intent with ACTION_CALL to make call in my app:
str="tel:0123456789";
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(str));
startActivity(intent);
But it pops up the system dialing screen. I understand this is built into ROM and can not be customized. But Can I hide this screen and keep the user staying on my activity?
Did some googling and research here. But no clear answer so far.
It looks like you can't customize the dialing screen, but you can use a PhoneStateListener to get certain information about the phone call. See this link.

Launch activity from background app

I have my app running in the background and I want the app to be shown on the top(launched) of the android phone when the code below is ran. (I know the code is ran for sure)
This seems like a simple thing but I spent a couple hours on this site and everyone seems to be suggesting something like this:
Intent intent = new Intent(myActivity.this, myActivity.class);
startActivity(intent);
However, it is not bringing the app to the front and launching it.
I got it to work from a PendingIntent launched from a notification. Which I done by the code below. But I want the app to launch by itself without the user clicking on the notification.
Intent intent = new Intent(myActivity.this, myActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, REQUEST_CODE, intent, 0);
notification.setLatestEventInfo(this, "title", "msg", contentIntent);
I also tried:
Intent intent = new Intent("android.intent.action.MAIN");
startActivity(intent);
and flagging the intent:
intent.setFlags(Intent.FLAG_FROM_BACKGROUND);
intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
But doesn't seem to do anything, any help appreciated.
You should be able to call your own application like this:
Intent intent = new Intent("android.intent.category.LAUNCHER");
intent.setClassName("com.your.package", "com.your.package.MainActivity");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Edit: Forgot to add intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
From what I understand, you want a service that is running in the background and on a certain event, you want your application's activity to come in front i.e. on the users current screen whatever he is doing. It is not advisable to let a background service launch an application without a user's action. The android developer website says
A status bar notification should be used for any case in which a
background service needs to alert the user about an event that
requires a response. A background service should never launch an
activity on its own in order to receive user interaction. The service
should instead create a status bar notification that will launch the
activity when selected by the user.
Hence, do not try to make it launch on its own.
I An not behind my laptop atm so I am nog sure, but I think you have toe pass a context object hand then do context.startactivity(intent);
Sorry for not wel formated I am at my phone atm
Hope It helps
I am clutching at straws here, but you wrote:
MyActivity is launched first, then I either navigate to another app or just hit the home screen to have my app running in the background.
So the situation is that your original Activity is NOT running in the background, when you pressed HOME it might well could have been stopped and destroyed. Your background task remained orphan and MyActivity.this is null at this point.
Try and test what does Log.i(TAG,MyActivity.this); print into LogCat.
I ended up using a pending intent and instead of stright up trying to use a intent.
Something like this: seems a lot more simple.
Intent.send(this, 0, intent);
Thanks.
Also, I’ve seen since compileSdkVersion 29 it's not possible, unless a few restrictions:
The activity started very recently.
The app called finish() very recently.
Through a PendingIntent, but only after a few seconds after the notification was sent.
The app has been granted the SYSTEM_ALERT_WINDOW permission by the user.
...
https://developer.android.com/guide/components/activities/background-starts

Sending a running application to background programmatically

Is it possible to send a activity into background programmatically in android?
I am creating a prank application that plays funny sounds after a specified time (input by the user). And I don't want the application to be visible when playing that sound and also the display should be dark.
Yes.
You can use either:
boolean sentAppToBackground = moveTaskToBack(true);
if(!sentAppToBackground){
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
this.startActivity(i);
}
More information here: http://developer.android.com/reference/android/app/Activity.html#moveTaskToBack(boolean)
Or simply:
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
this.startActivity(i);
According to Romain Guy a Android Framework Engineer, "You cannot simulate a press on the Home key.". So beware...
Check: http://osdir.com/ml/Android-Developers/2010-03/msg01887.html
Updated this answer according to: moveTaskToBack(true) returns false always
This function ultimately works for you
moveTaskToBack(true)
Or download source code . Android minimize app programmatically
Maybe play the sound from a service instead?
To expand on the answer by #ns476, the reason you should play it from a service is that any Activity that is no longer in the foreground can be killed at any time by the OS. Please review the activity lifecycle.

Android: Starting An Activity For A Different Third Party App

I'm working on an app and I want to integrate the Last.fm app into it. Basically, when someone is looking at an artist in my app, I would like to have a button that they can tap to open up Last.fm application with the artist's information.
This intent works, but it loads a menu asking which app I would like to use (Browser or Last.fm):
Intent i = new Intent();
i.setData(Uri.parse("http://last.fm/music/" + headliner));
i.setAction("android.intent.action.VIEW");
startActivity(i);
However, I just want to start the Last.fm app and skip the dialog asking which app to use, I thought maybe using the setPackage() method would work like this:
i.setPackage("fm.last.android");
But it causes the app to crash:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://last.fm/music/Rihanna pkg=fm.last.android }
Is it possible to just start the Last.fm app? Here's a copy of Last.fm's AndroidManifest.xml for reference.
Thanks for reading,
Tony
Yes, it's possible but you need to know the correct component name. Launch the last.fm app regularly and check the logfile for the cmp=... information that's been used when the app is started. Use this as well in your app then.
I start the Z-DeviceTest app from the market from within my app without a problem like this:
final Intent intentDeviceTest = new Intent("android.intent.action.MAIN");
intentDeviceTest.setComponent(new ComponentName("zausan.zdevicetest","zausan.zdevicetest.zdevicetest"));
startActivity(intentDeviceTest);
in my case the info I took from the logcat was:
// dat=content://applications/applications/zausan.zdevicetest/zausan.zdevicetest.zdevicetest
// cmp=zausan.zdevicetest/.zdevicetest
in order to know how to start the app with the right component/class... do the same for the last.fm app
Edit:
I've tested to launch Last.fm from my own app, and this works fine without any errors:
final Intent intentDeviceTest = new Intent("android.intent.action.MAIN");
intentDeviceTest.setComponent(new ComponentName("fm.last.android","fm.last.android.LastFm"));
startActivity(intentDeviceTest);

Categories

Resources