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.
Related
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.
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?
I created an example project here:
https://github.com/amitishai/Android-notifications
Here is the scenario:
Open app
Press button
Exit app
Click on the notification that was created. When the app opens you will be in Activity "Bla".
Press the OS BACK button.
Long press the OS Home button in order to see the open apps.
Click on the app.
You will see that you have entered Activity "Bla" again, and the text is the same.
If the activity was initially created with the intent, and then destroyed, how is the intent not null when restarting the activity?
The solution was to use Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
Example is here:
Android: Starting app from 'recent applications' starts it with the last set of extras used in an intent
So I have a basic notification application. Here's the current configuration details:
GCMIntentService
NotificationActivity
:
---->ViewMessageActivity
:
---->ViewUserDetailsActivity
GCMIntentService is configured to do the following: Upon receiving a notification, a pending intent with PendingIntent.FLAG_ONE_SHOT is created and the intent adds the Intent.FLAG_ACTIVITY_NEW_TASK flag.
Currently, I have my NotificationActivity defined in my manifest as android:launchMode="singleInstance". If I set it to android:launchMode="singleTop", when the user clicks the notification a few things can happen depending on Android Version (or so my two devices show)
In Android < 2.3, If I'm in another activity (say ViewMessageActivity) and I press the notification from the shade, nothing happens (I don't receive anything from onNewIntent)
In Android 4.2 (Not sure about other versions), If I'm in another activity (say ViewMessageActivity) and I press the notification from the shade, nothing happens (I don't receive anything from onNewIntent) AND the notification disappears from the shade
If I'm in NotificationActivity everything works great regardless of version
So this led me to set it to singleInstance instead of singleTop. Now when the user presses the notification and the user is in a different activity (say ViewMessageActivity), the notifications intent is handled appropriately HOWEVER, my NotificationActivity tries to create a new instance of ViewMessageActivity for the message clicked in the notification shade and it does not create a new activity. Instead, shows my already opened instance. I've tried adding flags such as Intent.FLAG_ACTIVITY_NEW_TASK but neither my onCreate or onNewIntent methods are called in my ViewMessageActivity.
Ideally, this is what I would like to happen: When the user has navigated to another activity (say ViewMessageActivity) from the main activity (NotificationActivity) and the user presses a notification from the notification shade, I would like the NotificationActivity to be flagged to update its ListView view onNewIntent which will create another ViewMessageActivity instance. Note: I have no launchMode option set for any other activity.
Any suggestions?
Vince
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.