FacebookActivity did not call finish() on Api 23+ - android

I am using facebook sdk in my app. In order not to show the solo progress bar when facebook button is clicked, I am using:
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:theme="#android:style/Theme.NoDisplay"
</activity>
However, I think for devices with api 23+ this causes a crash:
"com.facebook.FacebookActivity did not call finish() prior to onResume() completing"
Someone said here:Activity did not call finish? (API 23) by writing:
#Override
protected void onStart() {
super.onStart();
setVisible(true);
}
in the problematic activity, they solved the issue. But since I cannot edit FacebookActivity, is there any alternative solution?

Facebook have changed their instructions for initially setting up your project. Just change the theme for the com.facebook.FacebookActivity to #android:style/Theme.Translucent.NoTitleBar.

See javadoc of windowNoDisplay :
(...)your activity must immediately quit without waiting for user interaction(...)
So exception is correct, your use case does not match windowNoDisplay.

This is platform bug.
If you have been using Theme.NoDisplay in one or more activities in
your app, and you have not tested them on Android 6.0 yet, I recommend
that you do so soon. An undocumented regression in Android 6.0 will
cause some of those activities to crash upon launch, if your
targetSdkVersion is 23 or higher.
See this blog post: https://commonsware.com/blog/2015/11/02/psa-android-6p0-theme.nodisplay-regression.html

Related

How to set different - 2 configChanges for one android activity in android manifest file or any other way

Different configChanges for different android os version for single activity
<activity
android:name=".Activity_JoinMeeting"
android:configChanges="orientation|screenSize|layoutDirection|locale"
android:screenOrientation="landscape"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustPan|stateHidden"/>
configChanges for android OS 23 I want set set 4 properties and configChanges for android OS above 23 I want set 2 properties
how can I achive it
You can define two different activity in AndroidManifest file one for above android api 23 and other for rest android apis.
and launch that activies after checking api,
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP){
}
You can check the answer of aorlondo in this post and maybe try this solution with each properties you want to change.

Hide the screenshot from the Overview/Recent screen

When Android backgrounds an application it creates a screenshot of the current screen. The screenshot is displayed when you click the Overview button.
Is there a way to prevent this backgrounding screen shot (as if I'd used FLAG_SECURE), but allow the users to take screenshots?
You can configure not to show your activity in recent list. Add following code in manifest :
<activity
.....
android:excludeFromRecents="true"
...../>
Or from java code startActivity with flag:
intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Or,
<activity
.....
android:noHistory="true"
...../>
Try this https://stackoverflow.com/a/49442984/5939067 .
The solution above simply sets the secure flag when your app goes background, and clears it when it resumes(so you can take the screenshot while using the app).
It works perfectly for me. I tested with Samsung Galaxy 9+(Android 9), LG V30(Android 8) and LG G7 ThinQ(Android 8).

Android exclude from recents not working

I have an activity that I want not be seen in the Recents items. I have used the following in my Manifest file :
<activity
android:name=".WidgetLayout"
android:excludeFromRecents="true"
android:launchMode="singleInstance"
android:screenOrientation="portrait"
android:theme="#style/Theme.AppTheme.Dialog">
It works perfectly well on all android versions but when I try it on Lollipop (SDK 21) it shows up always in the Recent items. So is it an OS bug as stated by many or I have made some error. Is there a solution to the problem if yes then how can I solve it ?
This is a known issue into Android 5.0, since L preview.
Try with android:taskAffinity
android:taskAffinity=".WidgetLayout"
android:excludeFromRecents="true"
You Should try adding android:autoRemoveFromRecents="true"

way to exit from the app in android

I have a HomeActivity (for show splash screen in 3 seconds) , then automatically redirect to LoginActivity (for check users information for login).
In LoginActivity I have a exit button for exit the app, with below code
// TODO Auto-generated method stub
finish();
android.os.Process.killProcess(android.os.Process. myPid());
System.exit(0);
I used the same code in onDestroy() again.
But , when I try to exit from the app , Program is firmly closed. but remains in memory (in background app list ). How can I solve it?
It's not a good idea to call:
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
because android will handle processes automatically.
Also exclude your app from recent isn't a correct behavior.
By the way you can put under your "exit" activity tag in manifest:
android:excludeFromRecents="true"
And it will not appear in recent apps when the app is closed
EDIT
If it doesn't work in Android 5.0 it was a reported bug, so add taskAffinity property and use autoRemoveFromRecents:
android:taskAffinity=".YourExitActivity"
android:autoRemoveFromRecents="true"
Then in your onPause() you can check the sdk version to use finishAndRemoveTask:
if(android.os.Build.VERSION.SDK_INT >= 21) {
finishAndRemoveTask();
} else {
finish();
}
finish() is enough.
If the app still remains in memory after call finish(), it may be Memory leak in your app.
While mentioning tag in manifest we can keep
`android:`noHistory=true
so that mentioned activity wont be in back stack.
For example:
<activity
android:name="Splash_Activity"
android:label="Splash"
android:noHistory="true" />
You can call just finish() to close activity.

Android launches system settings instead of my app

For some reason whenever I (try to) start my app the phone decides to launch system settings instead of my "main activity". And yes, I am referring to the "Android system settings", and not something from my app.
This only happens on my phone, and I suppose it probably could be related to the fact that my app had just opened system settings when I decided to re-launch with a new version from Eclipse.
It is possible to start the app from within Eclipse, but when I navigate back from the app it returns to the system settings rather than the home screen, as if the settings activity was started first and then my activity. If I then start the app from the phone all I get is system settings yet again.
The app is listening to the VIEW-action for a specific URL substring, and when I start the app using a matching URL I get the same result as when I start it from Eclipse, app starts, but when I return I return to settings.
I have tried googling for this problem, and all I could find was something about Android saving state when an app gets killed, but without any information on how to reset this state. I have tried uninstalling the app, killing system settings, rebooting the phone, reinstalling, clearing application data.. no luck..
For what it's worth, here's the definition of my main activity from the manifest,
<activity android:name=".HomeActivity" android:label="#string/app_name" android:screenOrientation="portrait" android:clearTaskOnLaunch="true" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:pathPrefix="/isak-web-mobile/smart/" android:scheme="http" android:host="*"></data>
</intent-filter>
</activity>
And here is the logcat-line from when I try to start my app, nothing about any settings anywhere.
I/ActivityManager( 1301): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=se.opencare.isak/.HomeActivity }
When I launch from Eclipse I also get this line (as one would expect),
I/ActivityManager( 1301): Start proc se.opencare.isak for activity se.opencare.isak/.HomeActivity: pid=23068 uid=10163 gids={3003, 1007, 1015}
If it matters the phone is a HTC Desire Z running 2.2.1.
Currently, this is my HomeActivity,
public class HomeActivity extends Activity {
public static final String TAG = "HomeActivity";
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "onActivityResult(" + requestCode + ", " + resultCode + ", " + data + ")");
super.onActivityResult(requestCode, resultCode, data);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate(" + savedInstanceState + ")");
super.onCreate(savedInstanceState);
}
#Override
protected void onDestroy() {
Log.d(TAG, "onDestroy()");
super.onDestroy();
}
#Override
protected void onPause() {
Log.d(TAG, "onPause()");
super.onPause();
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
Log.d(TAG, "onPostCreate(" + savedInstanceState + ")");
super.onPostCreate(savedInstanceState);
}
#Override
protected void onPostResume() {
Log.d(TAG, "onPostResume()");
super.onPostResume();
}
#Override
protected void onRestart() {
Log.d(TAG, "onRestart()");
super.onRestart();
}
#Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
Log.d(TAG, "onRestoreInstanceState(" + savedInstanceState + ")");
super.onRestoreInstanceState(savedInstanceState);
}
#Override
protected void onResume() {
Log.d(TAG, "onResume()");
super.onResume();
}
#Override
protected void onStart() {
Log.d(TAG, "onStart()");
super.onStart();
}
#Override
protected void onStop() {
Log.d(TAG, "onStop()");
super.onStop();
}
#Override
protected void onUserLeaveHint() {
Log.d(TAG, "onUserLeaveHint()");
super.onUserLeaveHint();
}
}
Nothing (of the above) is written to the log.
After reading Blundell's response I have tried changing the launchMode/clearTaskOnLaunch settings, with the following results,
Situation A - I remove launchMode and clearTaskOnLaunch: same problem as before
Situation B - I remove clearTaskOnLaunch and keeps launchMode="singleInstance": another problem
Open app - My HomeActivity is showing
Click on a button to open another activity within my app - it opens as it should
Click on the system back-button - it returns me to system settings
Click on the system back-button again - I am returned to my HomeActivity
Another click on the back-button brings me back to the Android home screen
Situation C - I remove only launchMode and keeps clearTaskOnLaunch: same problem as before
Sitatuion D - I remove clearTaskOnLaunch and set launchMode="singleInstance": same as situation B
You are not calling setContentView() from the HomeActivity (as per the code added by you). And when it is not present, different device behave differently, like on emulator you will see "Application not installed on your phone". Try setting content view.
I've tested this on my phone, but this seems to work correctly here...
What if you try to create a new project, and then just copy the code into it?
It worked for me, maybe it will work for you to...
I suspect it has something to do with your change of version of Eclipse, which might use some different setting from the version you used before, therefore rendering your initial set-up as useless...
My 2Cents
You could look into the launch activity of the Application.
Basically what I think might be happening is, your app is being launched in the same 'Stack' as the settings was, therefore the OS will push the settings to the screen and then load your activity on top of that stack.
You could try adding:
android:launchMode="singleInstance"
into your <activity /> tag of your manifest file. This will start a new stack for your application and only your application
This may fix the issue but there may be another cause and this may cause adverse effects depending on how your app works. Have a look at the documentation for further info:Android:LaunchMode
EDIT
Reading your manifest, why not just remove android:launchMode="singleTop" and let it launch with the default?
Also you are pairing this with:android:clearTaskOnLaunch , because the OS has the settings activity and your activity as the same task it may be clearing it down to the 'root' activity which is the settings and not your app. Is there a reason you have this, remove it and try again?
Please note that I am not an Android developer, but I own an Android phone and think this issue is quite interesting.
To sum it up what I have read about this issue so far here it looks for me that following may be the root cause of this issue:
You use clearTaskOnLaunch, which wipes out all intents/activities/tasks/whatever_buzzword_is_used_for_this when your application starts.
Android then seems to remember permanently the last state of the application in some (what I now will call) global internal state database (GISD for brevity) which cannot be wiped that easily (at least not with uninstalling the application, rebooting, clearing intents, etc.).
Android tries to reopen the application with it's last state. If there is no current activity then this info is taken from the GISD, hence in your case it is "system settings".
There is no way (or it is unknown how) to wipe the state held in the GISD. (Your question is how to do that.)
If this is true this is clearly a phone issue, a major bug in Android, as you then can probably brick applications! All you must do is following:
Somehow provoke a similar thing like clearTaskOnLaunch - which should be possible - for the application you want to brick.
Trick the application to launch to some other application like "System settings" - many applications do this to enable WiFi or similar, but I think some clever people (read: not me) will find a way to do this for virtually any application
Now kill the application in this state.
Android will remember that state then in the GISD and if you try to launch the application from Home screen this will fail in future. Nice.
However even in the absence of a fix hopefully it is possible to bring back the application the same way:
Start your application with an Activity such that it launches. As you write, this works for you.
Apply what clearTaskOnLaunch does. (I really have no idea how, but you as Android developer probably know.)
Let your application launch a third application such that this third application becomes the global state.
Kill your application.
Perhaps timing and sequence is important, so perhaps you have to leave the third application after your application is killed, perhaps you have to pull the battery of your phone at the right time, perhaps you must use some weird ADB stuff to prevent your phone to do the right thing, perhaps you need another sequence of actions or somethign still is missing, whatever, even finding out how to provoke your type of error can be difficult - but thanks to your finding we know there is such a thing.
If you can make Android launch the third application from Home screen instead of your app this would confirm, that you indeed can fix that issue. If this does not work, so it is impossible to prevent Android to invoke system settings instead of your app, then Android certainly has a big problem, as it is likely someone finds a way to permanently brick apps in all those precious phones out there (ab)using that bug.
If the previous step works, however, the last step now is to let this third application launch back into the main screen of your application:
Start your application.
This will launch the third application.
Apply what clearTaskOnLaunch does.
Let the third application launch your application's main screen (or whatever you want)
Kill the third application (and perhaps your application).
Now the global activity state shall be set back to your application again - if everything goes well third application should not be harmed either.
Note that I am not sure this really can be done, as I am not able to test it myself. And having said that all, I agree that we certainly need be a better way to repair this issue!
But interesting would be to see what happens, if your app has the state of the third app and the third app has the state of your app. Does this lead to an endless loop?
Interesting too is, what happens if you deinstall the third app. Does this clean the automatic launch into that application or does it leave you helpless?
As an Android Phone onwer (only), I must say, that's quite a nice mess you have found. And that's why I am highly interested if there is a fix, as doing a factory reset cannot be considered a solution. Read: This is not only a developer problem, it affects Android users as well.
PS: Please forgive me my bad English, the length of this post, not using the right Buzzwords and posting on an issue which I am not an expert of so that my answer is a little bit OT. However I do this with HTH.

Categories

Resources