user458295
user458295

Reputation: 1279

Two or More Activities in android

I am using Button in main Activity. When i clicked this button it will go for another Activity. My question is.. when i clicked the Button it should not display another Activity window..For example..in my case when i clicked the button it will start another activity and in that Activity i have added functionality of Receiving Notification..Here What i want is When i clicked the button i should receive notification and it should display another Activity window. how can i do this..?I can do this my adding functionality of receiving Notification in Onclick. But I wont want in that way. I require two Activities..Please can any one suggest me how to do this.?

[CLARIFYING TEXT].

With in my first Acticity i had a Button. when i click that button it will start new Activity..ie.

Intent intent = new Intent(this, SecondActivity.class); 
startActivity(intent);

with in this second Activity i added the code for receiving notification..

Now my question is when i am clicking the button in first Activity a new window will be displayed as i am starting second activity..What i want is i wont want a new window to be displayed..But i have to receive notification..

Upvotes: 0

Views: 1309

Answers (1)

user433825
user433825

Reputation:

I don't really understand what you're asking, but I think one of these should solve it:

1) When the button is clicked use intents to open the activity: in onClick():

Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);

this requires you've added the second activity as an activity to the app manifest file.

2) if you want the second activity to open only when it receives the notification, use a service, then when you get the notification, bring the service to the foreground, but this will happen (unless you stop it) in an app, not just your own.

Intents Services Opening other activities

Upvotes: 1

Related Questions