Facebook Messanger Integration - android

I am working on Facebook messenger integration. When a user presses the reply button in Messenger, it navigates to my app's second screen. After that, when I select another image in the grid view on the main screen and move to the second screen again to send to Messenger, then the reply functionality is not working and it closing the second screen due to MessengerUtils.finishShareToMessenger() with out any warning and error. Reply will be appreciated.

look at here you might be get some tips. and use socialauth sdk
http://www.3pillarglobal.com/insights/part-1-using-socialauth-to-integrate-facebook-api-in-android

MessengerUtils.finishShareToMessenger(ACTIVITY, shareToMessengerParams);
Here, ACTIVITY is the activity that received the original intent from Messenger i.e the first activity in your case.

Probably you have android:launchMode="singleInstance", but
Activities that run with this launch mode don't allow others to start them for a result.
so
you need to change your launchMode of activity in AndroidManifest.xml to android:launchMode="standart" or android:launchMode="singleTop"
Similar question

Related

Android completely force quitting an app

I have a login activity. After login, the Main activity is started, which uses fragments for user navigation. I want a button in the nav drawer of my main activity which will completely close the app
Now, I have seen many many threads on this and have tried implementing their solutions. For example:
I have tried finishAffinity() in my Main activity, which should close the current activity as well as all parent activities
I have tried using finish() on the Login activity as soon as I bring up the Main Activity, and then calling finish() again when the user clicks the button
The highest voted answer for this question: Close application and remove from recent apps/, also does not seem work. First, android:autoRemoveFromRecents="true" requires API > 21, but even if I set the minimum SDK version to 21, the app still remains in the list
Finally, I have tried using an Intent when the user clicks the quit button and navigating back to the Login activity, and setting flags with an exit extra, and then finishing the Login activity (i.e. exit android application programmatically)
None of these are working. They will all close the Main Activity, and maybe even close the Login activity. But if the user clicks the app list/current apps/open apps key (the square soft key on most phones), the app is still visible there. When the app is clicked in that list it will take me back to the Login activity screen (I'm unsure if this is starting the app from fresh, or whether its just taking me to the previous Login screen which didn't close)
Out of desperation I have even tried System.exit(0), which I know is bad, but even that doesn't remove the app from the app list
So, how do I programmatically completely quit an app and remove all traces of it being open?
EDIT: I was too hasty in claiming one of the answers below didnt work (see italics above). The answer does remove the app correctly
I think this is the solution you're looking for.
You might consider having another activity named ExitActivity which will be called when you try to exit from your application. The trick here is, the ExitActivity will have android:autoRemoveFromRecents set to true in the manifest file, so that your instance will be cleared automatically from the recents.
Based on my research:
There is no way to force quite an application in android. You can only pause an activity. The discretion to quit an app lies totally with android framework which it does on checking the memory and resource utilization of apps. I could not find the official link for now, but I had read it earlier.
manage it by the OS. bring up the home screen.
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

Best way to manage a login workflow in a mobile app

I have some apps in Android that requires a login, but i'm not sure if i'm doing the login workflow in the correct way.
Basically, I have two activities LoginActivity and MainActivity. My default launcher activity is the MainActivity and in it's onCreate method I check if the user is logged in, if not I start the LoginActivity.
Another solution is make LoginActivity as default launcher activity and in it's onCreate method check if the user is logged in, if true, start the MainActivity.
Are two different architectures, and I like to know what is the best.
Thanks in advance.
The second one works best for me as i make the Login Activity act as a splash screen too, this gives me time to check for logged in user, and then whether to show the Login screen or to move to the MainActivity. This gives a more elegant user experience. But again, that's what works best for me. As what #NochinDeluxe already said, there is no "One Way" to do programming.
You can also go for a third approach. Make a splash screen where you can also initialise any libraries if required. Splash screen would then decide which activity to launch

Android startActivityForResult hide screen shot

In Android, I call startActivityForResult to start another activity, which is an email intent, and I also want to hide the screen shot for this new activity from Android task manager.
I know usually use Window.AddFlags(WindowManagerFlags.Secure) before SetContentView of Activity, but for the new activity from startActivityForResult, how to setup such flag?
Thx
which is an email intent
I am assuming that you mean "an Intent that will resolve to some third-party activity that happens to involve email".
I also want to hide the screen shot for this new activity from Android task manager
You are not the author of the other app. The decision of whether the other app should appear or not appear in the task manager is up to the developer of the other app, not you.
If you need this degree of control, do not display any activities from third-party apps.

Clear the activity stack before launching activity with intent

I'm working on C2DM notification for an Android Application and I'd like to open my application when user click on the notification. There is no problem for that, this is pretty easy.
The problem is that when the application is launching (after clicking on the notification), if some activity was previously opened, the launched activity seems to be added to the actual activity stack, what is a problem regarding to the complexity of my application (there is a lot of activity, some with static fields).
To solve the problem, 2 solutions would be OK:
1) Do not call a specific activity but just ask to my application to open (like when I click on the application icon on the home screen: Open the first activity if the application was closed or just bring the application to the front if was opened (but was in background)).
2) Clear all the activity stack and launch a specific activity.
But I didn't succeed to do one of both solution. Even using intent flag (like http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP).
Can somebody help me to solve this problem?
Thanks
PS: Sorry for my poor English, I'm from Belgium :-)
It's not what you asked to do but you can add the attribute android:launchMode="singleTask" to the activity you will be calling out of this notification and it won't create a new activity if one this instance already exists.
You could possibly also use the ActivityManager.killBackgroundProcesses(String packageName) to remove background processes but I have never tried this and it isn't advised or use the ChriZzZ suggestion and manage your activities a bit tighter.
Sounds like you are searching for FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
If set, this marks a point in the task's activity stack that should be cleared when the task is reset. That is, the next time the task is brought to the foreground with FLAG_ACTIVITY_RESET_TASK_IF_NEEDED (typically as a result of the user re-launching it from home)

Android - detecting application launch from home or history

What is the best way to detect when an Android "Application" has been launched from the Home screen/History screen?
Basically, what I'm trying to achieve is force the user to login to certain screens each time they come back to the app (i.e. they have full access to all activities once logged in, but essentially I want them to re-authenticate when they come back to the app via launching on the home screen).
I know similar questions have been asked before (i.e. how to log launches of an app) - but none that I have seen has yet been able to solve my problem. All ideas welcome...
What about
if((getIntent().getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY )!=0) {
Log.d(TAG, "Called from history");
}
?
This uses a simple Intent flag.
What is the best way to detect when an Android "Application" has been launched from the Home screen/History screen?
You can't, AFAIK.
Basically, what I'm trying to achieve is force the user to login to certain screens each time they come back to the app (i.e. they have full access to all activities once logged in, but essentially I want them to re-authenticate when they come back to the app via launching on the home screen).
Please use a sensible, user-friendly login system. For example, if you feel that their login credentials are stale based upon time, then force them to log in again. You can do this by checking the credentials in onCreate(), and if they are stale, call startActivity() to launch your login activity (or pop up your login dialog, or whatever is your means of logging them in).
Of course, an even better approach is to skip the login entirely. Unless this is a "password safe", a banking app, or something else that needs higher-than-average security, you do not need them to log in, and your users will get irritated if they feel that your login requirement is unnecessary. Most mobile applications do not require authentication.
Forcing a login based upon how they reached the activity is user-hostile. You are telling users that deign to use their phones for things other than your app that they are second-class citizens.
simply create a stump activity that doesn't have a content view and launches other activities on application start
e.g. put the following into onCreate:
Class<?> myclass;
if(isTimeForActivity1){
myclass = Activity1.class;
}else if(isTimeForActivity2){
myclass = Activity2.class;
}
startActivity(new Intent(this, myclass));
finish();
Try to look at the "OI Safe" application which has a well designed solution (I don't know if the code is well designed too, but, you'll look :p)

Categories

Resources