Skip to content

Latest commit

 

History

History
 
 

README.md

Android Notepad App

Android Notepad App is simple notepad app for android, written in Java. allows you to create, edit and delete notes locally using Room Persistence Library.

Table of Contents

Features

  • User can create a note.
  • User can edit a note.
  • User can delete a note.
  • When closing the browser window the notes will be stored and when the User returns, the data will be retrieved.

Getting Started

project structure:

	com.example.notepadapp
	├── AppExecutors
	├── MainViewModel
	├── Adapters
	│   └── NotesAdapter
	└── Database
	│ 	├── AppDatabase
	│ 	├── Notes
	│   └── NotesDao
	└── UI
	    ├── AddActivity
	    ├── EditActivity
	    └── MainActivity

Tools Used

  • Room Database.
  • Executor
  • View Model and Live Data.
  • Parcelable.

Room Database

Room provides an abstraction layer over SQLite to allow fluent database access while harnessing the full power of SQLite.

Apps that handle non-trivial amounts of structured data can benefit greatly from persisting that data locally. The most common use case is to cache relevant pieces of data. That way, when the device cannot access the network, the user can still browse that content while they are offline. Any user-initiated content changes are then synced to the server after the device is back online.

Further documentation

For a guide on applying Room's capabilities to your app's data storage persistence solution, see the Room training guide. And the CodeLabs Android Room with a View.

Additional resources

Executor

An object that executes submitted Runnable tasks. It's normally used instead of explicitly creating threads for each of a set of tasks. I have added the AppExecutor class and make it singleton so we always use the same instance of the class.

Additional resources

View Model and Live Data

ViewModel : Provides data to the UI and acts as a communication center between the Repository and the UI. Hides the backend from the UI. ViewModel instances survive device configuration changes. LiveData : A data holder class that follows the observer pattern, which means that it can be observed.

The Room persistence library supports observable queries, which return LiveData objects. Observable queries are written as part of a Database Access Object (DAO).

Room generates all the necessary code to update the LiveData object when a database is updated. The generated code runs the query asynchronously on a background thread when needed. This pattern is useful for keeping the data displayed in a UI in sync with the data stored in a database.

Further documentation

You can read more about Room and DAOs in the Room persistent library guide. And to understand View Model and Live Data more, check these videos: Android Jetpack: LiveData, Android Jetpack: ViewModel .

Additional resources

Parcelable

A Parcelable is the Android implementation of the Java Serializable. It assumes a certain structure and way of processing it. This way a Parcelable can be processed relatively fast, compared to the standard Java serialization.

To allow your custom object to be parsed to another component they need to implement the Parcelable interface. Like so,

public class Notes implements Parcelable { }

then implement its necessary methods.

Once you have implemented it in you object, you can put it into the extra of an intent.

        intent.putExtra("notes", new Notes("1","note-title","note-body"));

and to access the parcel on the other side,

        Intent intent = getIntent();
        notes = intent.getParcelableExtra("notes");
Further documentation

Resources