return from a launched activity in android - android

I'm trying to play a video using intents with the following code :
File file = new File("/sdcard/ted.mp4");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "video/mp4");
startActivity(intent);
This bit works fine but I doesn't return to the previous activity when the back button is pressed.
The first time it just restarts the video, but if it is pressed another time (on some devices 3 times) it will return to the previous activity (my main activity).
And I must mention that I don't mean quick successive clicks of the back button.
So how can I fix it, and why is it acting like this ?

try this way it may help you,
File file = new File("/sdcard/ted.mp4");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "video/mp4");
startActivityForResult(intent);

I Figured I have to add the flag FLAG_ACTIVITY_NEW_TASK and it will do the trick

Related

can't go back to the previous activity

This is how my app opens a page in default browser
Intent i = Intent.parseUri("http://www.google.com", Intent.URI_INTENT_SCHEME);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
Once the browser activity is active, I can't navigate back to my app using back button. It goes the activity before my app. My app/activity is not destroyed though as I can still resume it from the app list. I suspect my activity is 'removed' from the back stack somehow. Please help me debug/fix this. Thanks.
try to use Intent.ACTION_VIEW
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(myUrl));
startActivity(intent);

Confusing behaviour with intents in Android

I call GooglePlay from my app through an intent and again after I kill my own app:
Intent intent = new Intent(Intent.ACTION_VIEW);
String sModule = "market://search?q=pub:mycompany";
intent.setData(Uri.parse(sModule));
startActivity(intent);
finish();
android.os.Process.killProcess(android.os.Process.myPid());
Task manager shows, that only GooglePlay is running. My app isn't there anymore.
So my focus is GooglePlay at the moment. When going to the Desktop through the Home-Button and calling my App again it directs me to GooglePlay again.
Why is that? How can I call GooglePlay from my app independently?
I expected that when starting my app again, which I had previously killed, it would start my app and not focus on google play.
keyword is "launchMode" and "task".
this type of problems are so annoying and much complicated in android.
but this time you can try this.
Intent intent = new Intent(Intent.ACTION_VIEW);
String sModule = "market://search?q=pub:mycompany";
intent.setData(Uri.parse(sModule));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
if u cant solve, try combine another flags with FLAG_ACTIVITY_NEW_TASK.
cheers!

Failed to go back to home screen from Android apps

I have a button in my app named "Go Home" to redirect the user to the home screen. It is working fine without the very first launch. The process of first launch is noted below:
After uploading the APK into SVN I am downloading using the web browser. Then go back to the download folder and installing the app. When install finishes I click on Open. Then In my app I click on the "Go Home" button. The application redirect me to the web browser instead of the home screen. I am tired to search a solution for that.
I am using the following code:
finish();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
Thanks in advance, Siddiqui Noor
Your app is opening in the task of the browser. Try this:
finish();
Intent intent = new Intent(context, HomeActivity.class);
intent.setAction(Intent.ACTION_MAIN)
.addCategory(Intent.CATEGORY_HOME)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
try adding FLAG_ACTIVITY_NEW_TASK:
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
and also try putting finish() after startActivity
I'm pretty sure that it's not really redirecting you anywhere, it's just closing the Activity. You call finish() after which the intent to start the activity never happens. The app is closed because you've finished the Activity and you end up looking at the screen that was showing before you opened the app. In this case, that is the browser.
Try removing the line to finish();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
kill your current activity after redirect the next activity
finish();

How to remove application history in Android?

I have an application in which I want to show a custom activity(Access Denied) when user try to share an image.
When I am trying to share an image from default 'Downloads' application (For eg: share image through default message/gmail application) the custom activity is showed and exits 'Downloads' application.But next time when I launch the 'Downloads' application and press on an image the previously created draft mail/message is shown as the top activity.So it shows the custom activity always.
Launched the 'Downloads' application by using this intent.
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(new ComponentName(packagename,className));
startActivity(intent);
How can I fix this? I want to launch the 'Downloads' application as new (removing history of gmail/message etc.) every time.
Please try below code
Intent intent = new Intent(ClassA.this, ClassB.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);

Android Browser Intent back button

Hello I am lauching the browser from my application using an intent such as:
String url = "XXXX";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
but when I press back on the browser i want to go back to the my application, instead of going to the options of the browser. how can i control this behaviour?
You can't as the back button implementation is now under control of Browser Application.
Implement a WebView in your application and handle Back Key Pressed is the only option.
Try:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setData(Uri.parse(url));
startActivity(i);
A task (from the activity that started it to the next task activity) defines an atomic group of activities that the user can move to. Tasks can be moved to the foreground and background; all of the activities inside of a particular task always remain in the same order. You can find more about it here: http://developer.android.com/guide/components/tasks-and-back-stack.html

Categories

Resources