This blog is about technology, mainly Linux and Android. Mostly I shall share my own learning experience here. Tips and tricks, tutorials etc. I can't promise to be accurate here and welcomes all suggestions. I am getting these information from people and I am sharing it with you, so feel free to comment and spread this knowledge in rest of the world. Please experiment all advice on test systems, no guarantees :)

public boolean onContextItemSelected(MenuItem item) { // Call your function to preform for buttons pressed in a context menu // can use item.getTitle() or similar to find out button pressed // item.getItemID() will return the v.getID() that we passed before super.onContextItemSelected(item);

menu.setHeaderTitle(“Context Menu”); menu.add(0, v.getId(), 0, “Contacts”); } public boolean onContextItemSelected(MenuItem item) { // Call your function to preform for buttons pressed in a context menu // can use item.getTitle() or similar to find out button pressed // item.getItemID() will return the v.getID() that we passed before super.onContextItemSelected(item);

Kindly go through my previous post if you are not familier with above code.

We are here in onCreate method; setting the view by setContentView, getting the intent by getIntent, getting the note by getExtras and getString and assigning to second edit text. We are also registering the first edit text for a context menu.

onClickSend is the method registered for “Send” button. Here is the actual code for sending SMS Here we are creating PendingIntent which are a kind of callback mechanism in which we specifies the action need to be performed at a certain event later in lifecycle of application.

registerReceiver defines the method which needs to be performed in the case of event (SMS sent). It has two parameters one is BroadcastReceiver which actually holds the methods needs to be performed. When the onReceive overridden method is called it raises a Toast ( small info window) based on the return value of getResultCode which tells whether the action was prformed well.

Second parameter is a IntentFilter object.

Here’s the toast🙂

After that SmsManager.getDefault returns a sms manager object, which actually send the sms and also registers the PendingIntents.

Overriding onCreateContextMenu definesthe context menu which we have registered for text1 in onCreate. “Contacts” is the only menu item here.

In onContextItemSelected when we find this selected we start a new activity readAllActivity.

Here action, action2 and oldnote store the messages passed in intent either onClickTextView1 or onContextItemSelected. Based on action messages sent onClickSave will either delete the note and save the new, or just save the new note leaving old one intact.

Again lot of people helped from stackoverflow.com, many thanks to them.

I hope these post give a lot of learning to readers as they had been to mine. Of Course it’s still not perfect and we will keep improving it in future.

Thanks for reading.🙂

Update

Adding this functionality broke the old code. In EditNoteActivity.java we need to count number of messages passed in intent before trying to access the third message. As we send 2 message for normal editing and three for replace. Here is the code which will be in EditNoteActivity.java.

We have moved most of the functionality into onResume as this will be called when the Activity starts as well as each time Activity resumes. It’s mostly like old code except that it adds the button also dynamically through inflator. Also we are setting the setKeyListner to null as we don’t want it to be editable.

In onClickTextView1 we are creating a new intent and passing it along with key value pair of “ACTION” and “oldnote” to specify that a old note needs to be set in. We are also passing the note with EXTRA_MESSAGE. Similarly in addNote we are passing the “ACTION” AS “addnote”.

Here we getting the intent in onCreate which we passed from Myactivity.java in addNote or onClickTextView1 methods, by getIntent method. intent.getExtras returns the key value pairs we put inside the intent. Only if the “oldnote” is passed we retreive the note using EXTRA_MESSAGE identifier string. Rest is similar to what we did earlier.

Now run the app and we you will something similar.

No doubt there is still a lot of room for improvement, and we shall keep doing that.