Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using androidannotations to fire an intent

I have successfully used androidannotations @Extra to decode an intent and get the sent message as this snippet demonstrates:

@Extra(MyActivity.MESSAGE)
String intentMessage;

@ViewById(displayMessage)
TextView textView;

@AfterViews
protected void init() {
    textView.setText(intentMessage);
}

I'm missing how, if possible, to create the intent in the first place using annotations. e.g replace the following

Intent intent = new Intent(this,DisplayMessageActivity_.class);
intent.putExtra(MESSAGE, s);
startActivity(intent);

with something. Is this possible? (I'm totally new to all this so probably am missing something terribly obvious)

SOLUTION:

DisplayMessageActivity_.intent(this).intentMessage(s).start();

Where intentMessage is the name of the extra field.

like image 839
RichieHH Avatar asked Sep 11 '26 21:09

RichieHH


1 Answers

Yes, you can use the following:

// Starting the activity
MyListActivity_.intent(context).start();

// Building an intent from the activity
Intent intent = MyListActivity_.intent(context).get();

// You can provide flags
MyListActivity_.intent(context).flags(FLAG_ACTIVITY_CLEAR_TOP).start();

// You can even provide extras defined with @Extra in the activity
MyListActivity_.intent(context).myDateExtra(someDate).start();

// startActivityForResult() equivalent:
MyListActivity_.intent(context).startForResult();

Source: https://github.com/excilys/androidannotations/wiki/HowItWorks

like image 186
BVB Avatar answered Sep 14 '26 16:09

BVB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!