Return back to application - android

I have an application which works like Facebook Messenger. I can tray it and there is a small icon in the side of the screen which suppose to open the application.
I'm looking for a way to open my application without refreshing the whole Intent. I need a way to show the application as it was before the user trayed it.
User enters the application.
Starting a service of the tray icon.
App minimized (click the home button). tray apperas in the top left side of the screen.
Access another app and click the tray icon.
The tray icon should bring my application back to the main screen.
Currently, it bring the application back, but refresing my intent and all the values and texts I typed in my EditTexts are no longer there. It happens because I create a new intent:
Intent it = new Intent(this,MainActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(it);
so how I can resume my app without overwriting the current intent?

Related

App screen is freezes when It is opened from background service and phone screen is locked

I am opening my app from background when it receives a notification. For this I am using a service. Whenever my app is in background and a new notification comes, app will open automatically. It is working fine.
But when app is in background and phone screen is locked, now when a notification will come, it will show on screen(locked screen) and when user will open phone lock, my app's screen will be visible but screen will not responding, screen colour will also be like greyish layout on it.
To open app I am using a service, code is:
Intent serviceIntent = new Intent(getApplicationContext(), NewTaskService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(serviceIntent);
} else {
startService(serviceIntent);
}
In NewTaskService Class I am opening my app.
The resulted screen image when app is opened with notification from on lock screen is attached.
It seems like app is doing much work on main thread. Why don't you try to push your code in multi-thread or use Asynchronized class that handles everything in background
Basically, it was due to a dialog box. When app is opened and user unlocks mobile screen, dialog box disappears but screen is visible like there is a dialog box. Screen was not freezing or stucking, also the screen was greyish type due to that dialog box.
Because in such scenario dialog box view disappears.

Android - how to open a push notification deep-link intent that, when closed, returns to the Home screen?

I've created a receiver to receive and display push notifications - when the user presses on the push notification it opens a deep-link within my application. The problem is that when the user presses "back" he doesn't exit back to the home screen, but rather he goes to whatever screens for my application were open before on the application backstack - even if the application was minimized before he pressed on the notification.
The behavior that I need is for the user to be on the home screen, for him to open the notifications panel, press on my notification, go into the deep link page in my app, and when he presses the back button - I want him to exit all the way out to the home screen again. I don't want him in any way interacting with the backstack for the main application.
I've tried numerous combinations of flags for the pendingIntent in the push notification. Everything from FLAG_ACTIVITY_TASK_ON_HOME to FLAG_ACTIVITY_NEW_TASK to FLAG_ACTIVITY_SINGLE_TOP, etc. No combination seems to give me what I want - in every single case, opening the deep link with the app minimized will always return me to the next page in the history of the app when I press the back button. How can I solve this?
Example code:
Intent notificationIntent = new Intent(this, DeepLink.class);
notificationIntent.setData(Uri.parse(url));
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 1, notificationIntent, 0);
Solved. The deeplink class was starting an intent for each deeplink and these required that I set the flags NEW_TASK and CLEAR_TASK for each one. After that - everything worked.

How to open new activity every time i click the notification

Say, I have got 5 notification for an app. Now my application is in closed state. If i click on one notification, the application is opening the needed activity. But How to make the notification to open the new activity every time i click the notification even the app is open.
The app has a splash screen and the needed activity is the third child of splash screen.
I have implemented as follows :
On clicking notification will launch the splash screen with some boolean set if it comes from notification. I am opening the need activity from the splash screen according to the boolean.
If i click the notification when the app is already open, it again starts from the splash screen.
How to implement opening a activity from notification as it happens in whats app.

Starting launcher and moving to default homescreen

I'd like to start a specific launcher (set by the user), which is working fine with the code below. However, the launcher isn't moving to the user's "default" screen (e.g. the leftmost screen), but rather to the one where the user last left off. Is there a way to tell the launcher to move to the user's default screen upon opening? I've tried Intent.FLAG_ACTIVITY_NEW_TASK and Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED.
Intent home = new Intent("android.intent.action.MAIN");
home.addCategory("android.intent.category.HOME");
home.setClassName(launcherPackage, launcherActivity);
startActivity(home);
I solved this by sending the above-mentioned Intent twice (once to actually show the homescreen, and the second time to move the homescreen back to the default desktop).

Open an already opened Activity in android

I am developing an application and its Home Screen Widget.
Now from my widget when i press on a button it would open up my application from where it was left.
Means if i press home button during my application running then my application will go in background mode.
Now i want that it should resume my opened application.
Whenever i press a button from my Widget. How Can i Do it??
Please help
Thanks a bunch in advance!
I've never made a widget before, but this is how I've made a notification launch back into my original activity when you pull down the bar and click it.
Intent originalActivity = new Intent(getApplicationContext(), Widget.class);
originalActivity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
Once again, not sure how you would do this with a widget, but to relaunch it for a notification you convert that Intent into a PendingIntent to be called later when you want to launch back into it. I would assume this is a similar fashion for how you would it on a widget.

Categories

Resources