开发者

Call the same activity but with new parameters

I'm trying to create calendar for android. There is a month switcher (previous/next month). How can I call the same activity (which displays the calendar) with other parameters...

e.g. previous month will have CalendarMonth(java.util.Calendar.MONTH - 1)

and next month will have CalendarMonth(java.util.Calendar.MONTH + 1)

current month 开发者_开发问答will have nothing in costructor

Hope it's clear :)

Thanks for help in advance


If I understood correctly, this is what you want:

Intent myIntent = new Intent();
myIntent.setClassName("com.peter.calendar", "com.peter.calendar.CalendarMonthActivity");
myIntent.putExtra("month", "November");
startActivity(myIntent);

Use December instead of November, and you have effectively called your activity with different parameters. In the activity, just retrieve those extras to know which month the caller wanted.


You need to put the parameter in a bundle. and parse to the intent.

Bundle b = new Bundle;
b.put(....)
Intent intent = new Intent(this, newActivity.class);
intent.setBundle(b);
startActivity(intent)


you can use the flag Intent.FLAG_ACTIVITY_CLEAR_TOP

with the android:launchMode "singleTop"

and handle your new intent in : public void onNewIntent(Intent newIntent)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜