Android :: How To Make Notification Intent Resume Rather Than Making New One?
Jul 22, 2010
What I have here is a simple webview activity that when loaded it auto displays an ongoing notification. The idea is that people can navigate away from this activity and quickly access it again from any screen they want by pulling down the drop down menu and selecting it. Then when they want they can just close the notification by hitting the menu button and hitting exit and then the notification clears. This all works fine. However, when the notification is pressed it starts a new instance of the activity. What would I have to change to make it see if the activity has not already been destroyed and I can just call that instance back(resume it) and therefore not needing to load it again and won't need to add another activity to my stack.
package com.my.app;
import com.flurry.android.FlurryAgent;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.webkit.CookieSyncManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class Chat extends Activity {
private ProgressDialog progressBar;
public WebView webview;
private static final String TAG = "Main";
private NotificationManager mNotificationManager;
private int SIMPLE_NOTFICATION_ID;
@Override
public void onStart()
{ super.onStart();
CookieSyncManager.getInstance().sync();
FlurryAgent.onStartSession(this, "H9QGMRC46IPXB43GYWU1");
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chat);
mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
final Notification notifyDetails = new Notification(R.drawable.chat_notification,"ChatStarted",System.currentTimeMillis());
notifyDetails.flags |= Notification.FLAG_ONGOING_EVENT;
Context context = getApplicationContext();
CharSequence contentTitle = "Chat";
CharSequence contentText = "Press to return to chat";
Intent notifyIntent = new Intent(context, Chat.class);
PendingIntent intent = PendingIntent.getActivity(Chat.this, 0;
notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent);
mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);
CookieSyncManager.createInstance(this);
CookieSyncManager.getInstance().startSync();
webview = (WebView) findViewById(R.id.webviewchat);
webview.setWebViewClient(new chatClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setPluginsEnabled(true);
webview.loadUrl("http://google.com");
progressBar = ProgressDialog.show(Chat.this, "", "Loading Chat...");
}
private class chatClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.i(TAG, "Processing webview url click...");
view.loadUrl(url);
return true;
} public void onPageFinished(WebView view, String url) {
Log.i(TAG, "Finished loading URL: " +url);
if (progressBar.isShowing()) {
progressBar.dismiss();
} } }
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
webview.goBack();
return true;
} return super.onKeyDown(keyCode, event);
} @Override
public boolean onCreateOptionsMenu (Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.chatmenu, menu);
return true;
} @Override
public boolean onOptionsItemSelected (MenuItem item) {
switch (item.getItemId()) {
case R.id.home:
Intent a = new Intent(this, Home.class);
startActivity(a);
return true;
case R.id.closechat: mNotificationManager.cancel(SIMPLE_NOTFICATION_ID);Intent v = new Intent(this, Home.class);
startActivity(v);
return true;
} return false;
} public void onStop() { super.onStop();
CookieSyncManager.getInstance().sync();
FlurryAgent.onEndSession(this);
} } @Commonsware
Just to be sure I have it correct, is this what you were suggesting? I was a little worried about this line:
PendingIntent.getActivity(Chat.this, 0, notifyIntent, SIMPLE_NOTFICATION_ID);
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.chat);
mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
final Notification notifyDetails = new Notification(R.drawable.chat_notification,"ChatStarted",System.currentTimeMillis());
notifyDetails.flags |= Notification.FLAG_ONGOING_EVENT;
Context context = getApplicationContext();
CharSequence contentTitle = "Chat";
CharSequence contentText = "Press to return to chat";
Intent notifyIntent = new Intent(context, Chat.class);
PendingIntent intent =
PendingIntent.getActivity(Chat.this, 0, notifyIntent, SIMPLE_NOTFICATION_ID);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);
CookieSyncManager.createInstance(this);
CookieSyncManager.getInstance().startSync();
webview = (WebView) findViewById(R.id.webviewchat);
webview.setWebViewClient(new chatClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setPluginsEnabled(true);
webview.loadUrl("http://google.com");
progressBar = ProgressDialog.show(Chat.this, "", "Loading Chat...");
}
View 1 Replies
Sep 23, 2010
I need to put a Notification in the Status bar while my app is running, but I don't want it to call back to my Activity if selected. Its meant to just be info to the user that the app is running - basically a reminder in case they press the home button and minimize it.
View 1 Replies
View Related
Jul 2, 2010
I've got an app that creates an intent for the last.fm android app in which it will start the "recommended" station for my account when i press a button. The trick i'm trying to figure out is how do i get the phone back to my app without the user having to navigate back manually? Once it start the last.fm intent it takes you to the playlist and i need it to resume back to my app automatically.
View 2 Replies
View Related
Jul 23, 2009
I have an activity that is showing a video and when the user clicks a button, a new activity is launched. When the video activity stops, I pause the video view. When the video activity starts up again, I try to resume the video view videoView.start(), however, the video starts over from the beginning. I'm thinking that the buffer must be lost somewhere, so I now try to capture the current position via videoView.getCurrentPosition(), however, this is always returning 0.
Anybody know how to resume video playback when an activity starts up again?
View 5 Replies
View Related
Feb 26, 2010
I was just trying out with table layout to display some data....The data is a 3 column data and i want that the columns should utilize the whole width available. But it seems that the layout XML code which i had used is just wrapping up the columns according to the content.
Layout XML code
CODE:.........
View 1 Replies
View Related
Aug 13, 2010
I have read many examples of how to create notification messages.What i wanted to achieve, is because the notification will be executed by a widget, i would like the notification intent when clicked to clear it self when the user clicks on it.I do not have an activity to return to.The notification for my purposes will just plainly notify, nothing else.So what would be the code of an intent that just clear/cancel itself.The code below is an activity launched by a button(button code not included) the notification will be fired up by a background service.
View 2 Replies
View Related
Jun 9, 2010
I have a alarm thing going on in my app and it launches a notification that then when pressed launched an activity.The problem is that when I create more than one alarm then the activity launched from the notification gets the same extras as the first one. I think the problem is either with the intent i put in the pending intent or in the pending intent itself. I think I might need to put a flag on one of these but I dont know which one.The "details" extra is the same to every the next time a notification happens instead of having the different value.Until I set the intents I am sure that the correct value goes to the "details" so its a problem of getting the first intent everytime i press any notification. How can I make it to launch the correct intents?
View 2 Replies
View Related
Feb 24, 2009
I would like to know, if i can register for an intent or a notification that i could get every time android starts an application.
View 2 Replies
View Related
Jun 24, 2010
I looked around and I saw that other people were having an issue similar to this on other phones but mine is slightly different. Originally when I got the phone Google Talk played a sound every time i got a new message regardless if it was from a new person or someone i was already having a conversation with...I then turned on the vibrate option as well and ever since I did that the notifications even with a new message from a new conversation wont play or vibrate...any suggestions? Its even a bigger problem when my phone is plugged in b/c then I cant see the led flashing when i get a new message.
View 2 Replies
View Related
May 23, 2010
I have developed a very simple widget that was meant to interact with the user via an ImageButton. What I am trying to do now is as follows. When a user taps the button (after adding the widget to their home screen), I want the phone to dial a certain telephone number.
View 2 Replies
View Related
Feb 24, 2010
I am currently firing an Intent to a Broadcast Receiver which in turns starts an Activity.
Then from the same Service another Intent is fired to a Broadcast Receiver thats in the Activity.
The problem is that the Activity isn't getting the Intent meant for it because it is fired before it is alive and the Broadcast Reciever is registered.
I was wondering is there anyway to make sure an Activity is alive before sending an Intent?
View 1 Replies
View Related
Nov 23, 2010
I set an PendingIntent on a Notification (notification.setLatestEventInfo). this intent is actually the same intent used to launch my app, only with a flag that I put in the extra (intent.putExtra(TAB_INDEX_PARAM_NAME, UPDATES_TAB_INDEX)).
So my first activity launches, it queries it's intent's extras and immediately navigates to an Alerts activity rather the normal activity on a regular launch.
The problem: from this point, every activation of my app navigates to this Alerts activity. when debugged, I find that the flag is "stuck" in the intent even though I removed/changed it. it just won't change.
How can change an extra on a giving Intent?
View 2 Replies
View Related
Nov 12, 2010
I've got a receiver set up in my android application to catch android.intent.action.NOTIFICATION_REMOVE intents. On my Evo, it works fine - when a notification is cleared from the notification bar, I catch that event and can run some code. I tried running this on a Samsung Moment though, and it is never caught. So now I'm trying to figure out why, and I can't seem to find anything on Google about this intent action - and I set this code up a few months ago, so I don't remember where I even found this action, it doesn't seem to be in the API.
The evo is running 2.2, and the moment is running 2.1-update1, so I'm guessing that it's undocumented, and only available in 2.2. Is there any other way to catch an event that a notification has been cleared? Note that I'm not trying to cancel a notification that I put up, or trying to cancel another app's notification, just catch an event when a notification has been cleared.
Here's my receiver in AndroidManafest.xml:
CODE:....................
View 3 Replies
View Related
Apr 28, 2010
I need to push an intent to default camera application to make it take a photo, save it and return an URI. Is there any way to do this?
View 2 Replies
View Related
Mar 25, 2010
I have created an activity which sends a number of notifications to status bar. Each notification contains an intent with a bundle.
Here is the code:
CODE:..............
When user clicks this notifications, I read the bundle string "action" and performs that action. Here is the code:
CODE:.................
Everything works as expected. But, when I minimize the app using "arrow" button on device and then press and hold home button and clicks on my app icon the application starts and performs the same last action which have been performed by clicking the last notification. I figured out that when we click the app icon the application starts with last intent triggered by the notification.
View 2 Replies
View Related
Dec 2, 2009
Is it possible to get an intent when the user receives a mail and to cancel the gmail notification?
I want to filter some messages and I do not want to get notifications from them.
View 5 Replies
View Related
Dec 22, 2013
I recently updated my S3 to run Jelly Bean 4.3, and now when I receive a text it both vibrates and plays the notification sound rather than just the notification sound as it used to. I can't seem to find a way to turn this off?
View 1 Replies
View Related
Jan 19, 2009
I can use this code make outgoing call.
Intent dial = new Intent(Intent.ACTION_CALL); dial.setData(Uri.parse("tel:5556") );
context.startActivity(dial);
But how to detect call pick up the call or refuses to answer?
I tried PhoneStateListener but not working.
View 2 Replies
View Related
Jan 22, 2009
I'm having this problem with one of my apps where some people are reporting that their preferences are not being saved when they close and resume the app. The preferences theyre talking about happen to be actual Preferences (i.e. the built-in preferences manager for an activity). They say they're not doing anything special, just exiting the app and going back to it. Does anyone know why the prefs wouldn't be saved for only this select few people? I'm at a complete loss.
View 10 Replies
View Related
Jan 20, 2009
How to pause and resume the activity?
View 3 Replies
View Related
May 6, 2010
I am writing a simple android application with a class that extends activity, that plays a video from a url on the web. There is a button on top that on click takes the user to a web page.
What I want to do is when the user is browsing the web page, if he hits the back button, I want him to come back to the main activity and restart the video. Is there a way to do this?
Also, is there a way the video can be resumed from where it left off?
View 1 Replies
View Related
Aug 28, 2009
I am learning about OpenGL and managed to write a prototype game using VBO buffers. If I start the application from Eclipse or adb, everything works fine until I press the back or <Home> button. If I restart the application either by a long press on <HOME> and selecting my program or by restarting it from the applications, I sometimes get a black screen and the LogCat shows this error:
CODE:...............
I am aware that it is probably a wrong setting in my program's flow, but I am not fluently enough with OpenGL.
View 10 Replies
View Related
Mar 19, 2010
I have an AsyncTask that acts as a countdown timer for my game. When it completes the countdown it displays the out of time end screen and it also updates the timer displayed on the screen. Everything works fine, except I need to be able to pause and resume this when the pause button in the game is pressed.
If I cancel it and try to re-execute it, it crashes with an IllegalStateException.
If I cancel it and instantiate a new AsyncTask in its place the old one begins to run again and the new one runs at the same time.
Is there a way to cancel/pause the timer and restart it using AsyncTasks or is there a different way I should be going about doing this?
View 3 Replies
View Related
Feb 7, 2009
The reason I'm posting this question is because I cannot make a notification to reproduce a sound or a vibration sequence. For the case of the vibration I have permissions properly set and logcat do not show log message indicating a problem. For the case of sound, I have an mp3 saved in the res/raw folder and I always got an error saying: error loading sound in logcat. I add an snipped with the code Im using. Probably anyone can let me know if I am making a newbie mistake.
View 6 Replies
View Related
Nov 15, 2010
So i have my app running in fullscreen however i want to add a button that when pressed basically makes the notificationbar pop back up and imedeatly drop down so all notifications are visible, however i also want it to redisappear when its slide back up, is this possible?
View 2 Replies
View Related
Jan 22, 2010
I'm currently working with a two-activity application. The first activity allows the user to choose options for their upload, and the second activity displays a ListView of their results once processed.I have code in place that performs the uploads/downloads in the background, regardless of whether the application is currently in focus or not (thanks to Matthias Kaeppler's Droid-Fu).I would like to have my application Resume into my second (results) activity when a user clicks on the icon from the top-level launcher, regardless of how long they have been away from the app. I thought that the 'alwaysRetainTaskState' flag in the Manifest would do it, but I've not had success with that. Can anyone tell me how I need to set up my Manifest to get this functionality?
View 19 Replies
View Related
Mar 10, 2010
I wanted to know if it is possible to Detect in an Activitiy's OnResume if the Activity is resuming because the devices Back button was hit or not?
View 5 Replies
View Related
Jul 30, 2010
I'm calling this tasks:
CODE:.........
And here are the two TimerTasks:
CODE:........
As you can see, I just call a method after 5 resp. 10 seconds. From time to time I would like to pause the "countdown". This means i want that the time until the 5 seconds are passed isn't running anymore. And then in a later point in time, I would like to resume it. How can I achieve that?
View 1 Replies
View Related
Mar 15, 2010
Looking for an app to make my ringtone/notification sounds into profiles for work/school/home etc. I downloaded quick profile but it only changes my ringtones not my notification sounds.
View 4 Replies
View Related
Feb 6, 2010
I've an App which performs a potentially large download in background thread. When the orientation changes or the keyboard is opened the App lifecycle system invokes the start/stop/pause/resume etc calls - is there any strategy available to resume the download rather than just set a flag so the new onCreate() knows it was interrupted and has to start it again?
View 2 Replies
View Related