Reputation: 640
http://developer.android.com/guide/topics/ui/notifiers/notifications.html Page says that, I have to use Intent
I can't use Intent because my code have only one Activity. I want to use notification to get back to app e.g. from DEVICE'S HOME SCREEN.
I have to use Intents when I want to execute something by clicking the notification. Is there a way to use setContentView
after clicking the notification?
Upvotes: 0
Views: 914
Reputation: 27748
Without seeing what you have attempted so far, I am going to take a stab at this one.
I don't quite see why regardless of how many Activities you have in your app, you cannot declare / use an Intent
. If you need to trigger your only Activity again, after a Notification has been clicked, and need to call the setContentView(R.layout.some_layout_xml);
in the Activities onCreate()
again, why not declare an Intent for your Notification like this:
Intent intent = new Intent(getApplicationContext(), YOUR_ACTIVITY.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(YOUR_ACTIVITY.this, 0, intent, 0);
This way, clicking on your Notification should do what you want it to do.
Again, this may or may not work for you considering that you haven't posted any code at all.
EDIT: Based on the comments by the OP, what I think the solution maybe:
Refer to this link on how to send data with an Intent for a Notification: How to send parameters from a notification-click to an activity?
Basically, since a Notification
has been triggered, I am assuming that the user has already logged in. Now to skip the login part when they come back to the app after clicking a Notification
, send some extras along with the Intent
. Then, when the Activity
starts, check for the value and using an if...else
statement, decide which layout should be shown.
Again, and I cannot stress this enough, you should always show what you have done so far. That really helps finding a solution. Your actual requirement has no bearing on what you need done at all.
Upvotes: 2
Reputation: 10260
You can use an Intent to get back to the app, e.g. like this:
final Intent intent = new Intent(context, YourActivity.class);
final PendingIntent pendingIntent = PendingIntent.getActivity(
context, 0, intent, 0);
final Notification notification = new Notification(
R.drawable.logo, tickerText, System.currentTimeMillis());
notification.setLatestEventInfo(context, title, text, pendingIntent);
notificationManager.notify(NOTIFICATION_ID, notification);
Upvotes: 1