Found lots of similar questions but none that suited my situation.
Basically I have an Android app that flows like so:
HOME >> CHECKOUT 1 >> CHECKOUT 2 >> CONFIRMATION PAGE
Once we get to the confirmation page I want to 'finish' both checkout pages as I don't want the user seeing orders that have been submitted if they were to hit the back button. I know how to finish the Checkout 2 page once I confirm the order but I don't know how to 'cascade' down the stack to finish both.
When the user hits Back on the confirmation page they should go to the Home screen. I know how to do this with Intents but that's no good for the back button. Unless I override the back button behaviour and do something like:
Intent intent = new Intent(getApplicationContext(), Home.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
But I feel like this is very hacky. Anyone know the proper way to do it? Some sort of session variable that Checkout1.onResume looks for maybe?
Cheers
I ended up just overriding the onBackPressed method and using doing this
Intent intent = new Intent(getApplicationContext(), Home.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
I'll wait a while before marking the answer in case someone has a better way.
Related
https://developer.android.com/preview/privacy/background-activity-starts
From this, it results that my payment app, which shows an Activity when a NFC transaction is performed, will not be able anymore to show anything to the user.
Has anyone have a clue what would be the new approach ?
Thanks!
I currently use the NFC service and it starts an Activity intent.
Intent intent = new Intent(mApplicationContext, PaymentActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
mApplicationContext.startActivity(intent);
The Activity should be shown. It works now, but from Android Q, it won't
According to the link, if you are having a HostApduService, then your app should work the same in Android Q.
If that is not your case, the simplest work around is to get "Draw over other apps" permissions. You can open activities if the app has been granted the SYSTEM_ALERT_WINDOW permission by the user. I have tested this and working.
Technically, you are showing something on top of other apps without user's interaction, so this might be the right way to go.
I have an application and the launcher activity is a login activity. I want the user to be able to close the app in another activity and when he opens it again the application to start again from the login activity (in other words to close the app and not just send it to background).
I have found a lot of ways to close an app:
1.finish();
2. Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
3. finishAffinity();
4. finishAndRemoveTask();
5. System.exit(0);
and combinations of the above. Which one is more efficient? What is the best practice?
Use whichever one you like. System.exit(0) probably is the most efficient, being a system method that directly exits the JVM running your app.
Like if i want to redirect the user to Location service i have to use
Intent intent = new Intent(
Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
Now what shoulb the ACTION_ to let the user go to the data usage settings where he can enable the Mobile Data Traffic?
Are you sure you aren't looking for:
final Intent dataUsage = new Intent(Intent.ACTION_MAIN);
dataUsage.setClassName("com.android.settings",
"com.android.settings.Settings$DataUsageSummaryActivity");
startActivity(dataUsage);
Your title suggests that's what you want, but your comment suggests you wanted the network operator settings.
Let us say that user opens Twitter app and hits share button for a selected tweet. He then sees my app in the list along with other apps like Gmail, SMS etc.
In OnCreate method of my activity, I process the tweet. Remove short links etc and then call the PostActivity of twitter app. Below code then shows "My tweet" in compose tweet section of twitter app.
Intent intent1 = new Intent("android.intent.action.MAIN");
intent1.setComponent(new ComponentName("com.twitter.android","com.twitter.android.PostActivity"));
intent1.setAction(android.content.Intent.ACTION_SEND);
intent1.putExtra(android.content.Intent.EXTRA_TEXT,"my tweet");
intent1.setType("text/plain");
startActivity(intent1);
What i want to do is ,before i call PostActivity, i need make 100% sure that my activity was called from twitter app.
Currently I have a button that when pushed calls the Intent below.
Intent sharingIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sharingIntent.putExtra(Intent.EXTRA_EMAIL,
new String[] { toString });
sharingIntent.putExtra(Intent.EXTRA_SUBJECT,
"New Files from Safe Storage");
sharingIntent.setType("text/*");
startActivity(sharingIntent);
This intent then uses the default share activity to share the email with my attached file (which i took out for this example). When this code goes off it opens the gmail activity for me, but i still need to push the send button even though everything is filled in. Is there a way to make this instead just send automatically without showing the user the activity and having them forced to push "Send"?
Have a look on the following link, there is an answer for your question.
Sending Email in Android using JavaMail API without using the default android app(Builtin Email application)