I have some little problem with android. Just wanted to know how to call intents from an Adapter Class which just extends BaseAdapter and not Activity Class.
Retrieving data from intent Once you start the activity, You'll be able to get the data attached in the next activity [or services, BoradCast receivers.. etc] being started. to retrieve the data, we use the method getExtra() on the NextActivity from the intent.
An intent is to perform an action on the screen. It is mostly used to start activity, send broadcast receiver,start services and send message between two activities. There are two intents available in android as Implicit Intents and Explicit Intents. Here is a sample example to start new activity with old activity.
This example demonstrate about How to send data from one activity to another in Android without intent. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
To start an activity you need context. Try with the following approach
pass the context parameter to the constructor of the class which extends BaseAdapter.
public class MyAdapter extends BaseAdapter {
Context context;
public MyAdapter(Context context) {
this.context=context;
}
To start an activity use the following approach
Intent i = new Intent();
i.setClassName("com.abc.mypackage", "com.abc.mypackage.NewActivity");
context.startActivity(i);
or
Intent i = new Intent(context, MainActivity.class);
context.startActivity(i);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With