start activity quick but back to desktop - android

I have a quick click button to start activity by intent in my android application, it succeed to target activity ,but back to the desktop, I can not understand.
please guide me to resolve this.
Intent intent = new Intent(getContext(), ActivityDetailActivity.class);
startActivity(intent);
enter image description here
enter image description here

You need to call intent like this :
Intent intent = new Intent(MainActivity.this, ActivityDetailActivity.class);
startActivity(intent);

Related

How to clear previously opened activity in Android

Intent intent = new Intent(MainActivity.this, Payment.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Opening coupon activity to apply coupon:
Intent intent = new Intent(Payment.this, Coupon.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
From coupon activity opening payment activity with updated data
Intent intent = new Intent(Coupon.this, Payment.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
The problem is, when I click on the back button on payment activity after applying the coupon, it opens the previously opened payment activity again (not the main activity).
onBackPressed() I don't want to do it static (like Intent intent = new Intent(Payment.this, MainActivity.class); and also don't want to use finish(); in payment activity.
Please help.
You can use FLAG_ACTIVITY_NO_HISTORY when launching the Payment activity.
See: https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_NO_HISTORY
This is a Simple Use case of startActivityForResult don't make it complicated with Intent Flags and launch modes.
Whenever you Open your Activity Coupon just use startActivityForResult and upon applying coupon send the result back to previous Activity (success/failure) or whatever result you want . Then you can change the UI as per the result you got in onActivityResult() .
You can follow How to manage startActivityForResult on Android or the latest way from the doc Getting a result from an activity .

Adding Intent to class in Applozic's Messaging SDK

Where should I add the foll.intent
Intent intent = new Intent(this, ConversationActivity.class);
startActivity(intent);
As of now, I've followed Applozic's instructions on github. But I am stuck at this.
I've a MainActivity, ApplozicGcmListenerService Class, GcmInstanceIDListenerService Class,GCMRegistrationUtils Class.
When selecting a contact to chat, you can call the ConversationActivity.java to open the chat window.
For example,
Intent intent = new Intent(this, ConversationActivity.class);
intent.putExtra(ConversationUIService.USER_ID, contact_user_id);
intent.putExtra(ConversationUIService.DISPLAY_NAME, contact_name);
startActivity(intent);
Before starting ConversationActivity intent you need to make sure that you have done the Applozic registration.
Where should I add the following intent?
You can start ConversationActivity intent on click of button or an menu option click as your app use case and it will show the list of conversations you have done so far.
You can check this sample code link and we started the ConversationActivity intent on navigation drawer menu item click

Start Instagram Options Activity

My question is simple, Can i start Instagram's Options activity from another app (Where you can find friends, invite friends, change password, sign out...) via intent? Something like:
Intent insta_intent = getPackageManager().getLaunchIntentForPackage("com.instagram.android");
insta_intent.setComponent(new ComponentName("com.instagram.android", "com.instagram.android.activity.UrlHandlerActivity"));
insta_intent.setData(Uri.parse("http://instagram.com/settings"));
startActivity(insta_intent);
How can i do that?
I think, it would be something like this:
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.instagram",
"com.instagram.SettingsActivity"));
startActivity(intent);

Finish Current Activity and start a new one

I have a Fragment F. After getting result from a service, F needs to finish the activity it is in and launch a page in the web browser which I do using an intent.
It does seem to work fine if the user presses the back button. However, if he launches the app from recent apps, the activity isn't finished.
I have thought about otherways of doing it. Like finishing the current activity and opening the page from the parent activity. But I'll have to make a lot of changes in the flow. So that would be my last option. Is there any way to make sure that the activity is finished even when I launch it from recent apps?
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(url));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
getActivity().finish();
Edit: Added code.
try this code for start browser and clear all the stacks of your application
Intent intent = new Intent(); // need to set your Intent View here
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
getActivity().startActivity(intent);
getActivity().finish();
Updated
Try this attribute in your activity in AndroidManifiest.xml file
<activity android:name=".MainActivity"
android:excludeFromRecents="true" ...
use the following code
Intent intent = new Intent(getApplicationContext(), Home.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
this.finish();

How to go to the default home screen of Android programatically?

In my app, I have a button called EXIT, when the user clicks that, I want to finish all the activities of my app, which are in the stack, and go to the default home activity or the all apps activity.
I have written the following code in my onClick():
Intent intent = new Intent(Intent.CATEGORY_HOME);
startActivity(intent);
But it gives me the following error in logcat:
03-12 11:22:18.279: ERROR/AndroidRuntime(308): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.category.HOME }
So what do I need to do to achieve this? Do I need some configuration in the manifest or is my approach wrong?
Try this:
Intent homeIntent= new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory(Intent.CATEGORY_HOME);
homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(homeIntent);
use following code to launch home screen:
Intent intent=new Intent(this, HomeClass.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

Categories

Resources