Knowee
Questions
Features
Study Tools

Write steps for Linking activities using intents.d) Write the use of onCreate( ), onUpgrade ( ) and getWritable Database( ) methods. With example.e) Write an application to send Email(Using - To, Subject and Message) Intent.f) Explain List View using adapter with the help of example.

Question

Write steps for Linking activities using intents.d) Write the use of onCreate( ), onUpgrade ( ) and getWritable Database( ) methods. With example.e) Write an application to send Email(Using - To, Subject and Message) Intent.f) Explain List View using adapter with the help of example.

🧐 Not the exact question you are looking for?Go ask a question

Solution

d) The onCreate(), onUpgrade() and getWritableDatabase() methods are used in Android SQLite Database.

  • onCreate(SQLiteDatabase db): This method is called when the database is created for the first time. This is where the creation of tables and the initial population of the tables should happen. For example:
@Override
public void onCreate(SQLiteDatabase db) {
    String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "("
            + KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT,"
            + KEY_PH_NO + " TEXT" + ")";
    db.execSQL(CREATE_CONTACTS_TABLE);
}
  • onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion): This method is called when the database needs to be upgraded. It is used to drop tables, add tables, or do anything else it needs to upgrade to the new schema version.
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // Drop older table if existed
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS);

    // Create tables again
    onCreate(db);
}
  • getWritableDatabase(): Create and/or open a database that will be used for reading and writing.
SQLiteDatabase db = this.getWritableDatabase();

e) To send an email from an Android application, the Intent.ACTION_SEND action is used to launch the email client installed on your Android device.

Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{ "[email protected]"}); 
email.putExtra(Intent.EXTRA_SUBJECT, "Subject");
email.putExtra(Intent.EXTRA_TEXT, "Message");
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client :"));

f) ListView is a view group that displays a list of scrollable items. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database query and converts each item result into a view that's placed into the list.

public class MainActivity extends Activity {
    ListView listView ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Get ListView object from xml
        listView = (ListView) findViewById(R.id.list);

        // Defined Array values to show in ListView
        String[] values = new String[] { "Android List View", 
                                         "Adapter implementation",
                                         "Simple List View In Android",
                                         "Create List View Android", 
                                         "Android Example", 
                                         "List View Source Code", 
                                         "List View Array Adapter", 
                                         "Android Example List View" 
                                        };

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
          android.R.layout.simple_list_item_1, android.R.id.text1, values);

        // Assign adapter to ListView
        listView.setAdapter(adapter); 
    }
}

This problem has been solved

Similar Questions

Q4) Answer the following (Any Five) : [5 × 5 = 25]a) Explain architecture of Android.b) Write an application for the following Layout :Student InformationStud-idStud-nameStud-Markok cancelAfter clicking ok display detail on another activity.c) Write steps for Linking activities using intents.d) Write the use of onCreate( ), onUpgrade ( ) and getWritable Database( ) methods. With example.e) Write an application to send Email(Using - To, Subject and Message) Intent.f) Explain List View using adapter with the help of example.g) Differentiate between :i) Location based Services & Google Map.ii) Geocoding and Reverse geocoding.

Which among the following intent action helps us in sending email through Android? ACTION_SEND ACTION_MAIL ACTION_EMAIL

What is the 'Parcelable' interface used for in Android?ATo store data in a local databaseBTo pass data between activities efficientlyCTo implement custom viewsDTo manage the app's navig

Which of the activities below requires downloading information to your computer?*1 pointa) Putting a video on YouTubeb) Adding an image to a post on your social media feedc) Browsing a web paged) Posting a comment on Snapchat

For Activity 9, post your reflection on the material from the screencast and from the Web resources with some self-reflection. Your reflection should highlight key points you felt were important and focus on strategies you may not have encountered before viewing this material. It should also exclude two personal examples - one of an experience where you have used the best practices you explore this week and a second where you violated them. Remember that this course is a safe space, so please be honest without any fear of judgment.

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.