Wednesday, 28 September 2016

Nested RecyclerView or Inner Recycler View in android

Nested RecyclerView Example

Recyclerview is a flexible view for providing a limited window into a large data set.

I am going to display below layout using two recycler views(nested recycler views).





Follow below steps to achieve Nested/Inner Recycler view.

1.copy these dependencies and paste it to app level grade file

compile 'com.android.support:appcompat-v7:24.2.1'
        compile 'com.android.support:recyclerview-v7:24.2.+'
        compile 'com.android.support:cardview-v7:24.2.+'

make sure youd have 24+ android sdk.

/******************************************************************************/
2.copy these model classes

a.EventInformationClass, this class contains dates list and its events list

    public class EventInformation {
    
    private ArrayList<EventDates> eventsDatesList = new ArrayList<>();

    public ArrayList<EventDates> getEventsDatesList() {
        return eventsDatesList;
    }

    public void setEventsDatesList(ArrayList<EventDates> eventsDatesList) {
        this.eventsDatesList = eventsDatesList;
    }
}


b.EventDate class, this class contains list of dates(headings), it contains the list of events on that date.

public class EventDates {
    private String date;
    private ArrayList<Events> eventsArrayList;

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public ArrayList<Events> getEventsArrayList() {
        return eventsArrayList;
    }

    public void setEventsArrayList(ArrayList<Events> eventsArrayList) {
        this.eventsArrayList = eventsArrayList;
    }
}

c.Events class, this class contains event name and event id

public class Events {
    private String eventId;
    private String eventName;

    public String getEventId() {
        return eventId;
    }

    public void setEventId(String eventId) {
        this.eventId = eventId;
    }

    public String getEventName() {
        return eventName;
    }

    public void setEventName(String eventName) {
        this.eventName = eventName;
    }
}
/************************************************************************/

3.create layouts

a.activity_main.xml, this layout corresponds to main activity

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v7.widget.RecyclerView
           android:id="@+id/event_recycler_view_parent"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:scrollbars="vertical" />
</RelativeLayout>

b.event_list_parent_item.xml, this layout corresponds to parent info(here am showing only date and (parent)recyclerview)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:focusable="true"
    android:clickable="true"
    android:background="?android:attr/selectableItemBackground"
    android:orientation="vertical">

    <TextView
        android:id="@+id/event_list_parent_date"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <android.support.v7.widget.RecyclerView
        android:layout_below="@+id/event_list_parent_date"
        android:id="@+id/event_recycler_view_child"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         />

</RelativeLayout>

c.event_list_child_item.xml, this layout corresponds to list of events under each dates

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <android.support.v7.widget.CardView
        android:layout_margin="10dp"
        android:layout_width="match_parent"
        android:layout_height="48dp">
        <TextView
            android:id="@+id/event_list_event_name"
            android:paddingLeft="10dp"
            android:layout_gravity="center_vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </android.support.v7.widget.CardView>

</LinearLayout>

/***************************************************************************************/
4.create main activity, data is in json. you should import import org.json.*; to parse json into objects (i deliberately left some data. ex: id and name.)

public class MainActivity extends AppCompatActivity {

    RecyclerView event_recycler_view_parent;
    EventListParentAdapter event_list_parent_adapter;
    
    String jsonString = "{\n" +
            "    \"Id\" : \"1\",\n" +
            "    \"Name\" : \"Ganesha\",\n" +
            "    \"Location\" : \"Bengaluru\",\n" +
            "    \"Event info\" : [ \n" +
            "\t\t\t\t\t\t{\n" +
            "\t\t\t\t\t\t\t\"Date\" : \"29-9-16\",\n" +
            "\t\t\t\t\t\t\t\"events\" : [ \n" +
            "\t\t\t\t\t\t\t\t\t\t\t{\n" +
            "\t\t\t\t\t\t\t\t\t\t\t\t\"eventId\" : \"1\",\n" +
            "\t\t\t\t\t\t\t\t\t\t\t\t\"eventName\" : \"event one\"\n" +
            "\t\t\t\t\t\t\t\t\t\t\t}, \n" +
            "\t\t\t\t\t\t\t\t\t\t\t{\n" +
            "\t\t\t\t\t\t\t\t\t\t\t\t\"eventId\" : \"2\",\n" +
            "\t\t\t\t\t\t\t\t\t\t\t\t\"eventName\" : \"event two\"\n" +
            "\t\t\t\t\t\t\t\t\t\t\t}\n" +
            "\t\t\t\t\t\t\t\t\t\t]\n" +
            "\t\t\t\t\t\t}, \n" +
            "\t\t\t\t\t\t{\n" +
            "\t\t\t\t\t\t\t\"Date\" : \"30-9-16\",\n" +
            "\t\t\t\t\t\t\t\"events\" : [ \n" +
            "\t\t\t\t\t\t\t\t\t\t\t{\n" +
            "\t\t\t\t\t\t\t\t\t\t\t\t\"eventId\" : \"3\",\n" +
            "\t\t\t\t\t\t\t\t\t\t\t\t\"eventName\" : \"event three\"\n" +
            "\t\t\t\t\t\t\t\t\t\t\t}, \n" +
            "\t\t\t\t\t\t\t\t\t\t\t{\n" +
            "\t\t\t\t\t\t\t\t\t\t\t\t\"eventId\" : \"4\",\n" +
            "\t\t\t\t\t\t\t\t\t\t\t\t\"eventName\" : \"event four\"\n" +
            "\t\t\t\t\t\t\t\t\t\t\t}\n" +
            "\t\t\t\t\t\t\t\t\t\t]\n" +
            "\t\t\t\t\t\t}\n" +
            "\t\t\t\t\t]\n" +
            "}";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ArrayList<EventDates> eventDatesArrayList;
        EventInformation eventInformation = new EventInformation();;
        
         try {
             //pasing jason data
            JSONObject jsonObject = new JSONObject(jsonString);
            JSONArray jsonDatesArray = jsonObject.getJSONArray("Event info");
            eventDatesArrayList = new ArrayList<>();
            for (int indexDates=0;indexDates<jsonDatesArray.length();indexDates++){
                EventDates eventDates = new EventDates();
                JSONObject jsonDateobject = jsonDatesArray.getJSONObject(indexDates);
                String date = jsonDateobject.getString("Date");
                eventDates.setDate(date);
                JSONArray jsonArrayevents = jsonDateobject.getJSONArray("events");
                ArrayList<Events> eventsArrayList = new ArrayList<>();
                for (int indexEvents=0;indexEvents<jsonArrayevents.length();indexEvents++){
                    Events events = new Events();
                    JSONObject eventObj = jsonArrayevents.getJSONObject(indexEvents);
                    events.setEventId(eventObj.getString("eventId"));
                    events.setEventName(eventObj.getString("eventName"));
                    eventsArrayList.add(events);
                }
                eventDates.setEventsArrayList(eventsArrayList);
                eventDatesArrayList.add(eventDates);
            }
            eventInformation.setEventsDatesList(eventDatesArrayList);
            Log.d("message",eventInformation.toString());
        }catch (Exception e){

        }
        //parent recyclerview
        event_recycler_view_parent = (RecyclerView) findViewById(R.id.event_recycler_view_parent);
        event_list_parent_adapter = new EventListParentAdapter(eventInformation,MainActivity.this);
        event_recycler_view_parent.setHasFixedSize(true);
        RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
        event_recycler_view_parent.setLayoutManager(mLayoutManager);
        event_recycler_view_parent.setItemAnimator(new DefaultItemAnimator());
        event_recycler_view_parent.setAdapter(event_list_parent_adapter);


    }
}
/*******************************************************************************/
5.copy adapters
  EventListParentAdapter class, this used for parent data(date)
  
  public class EventListParentAdapter extends     RecyclerView.Adapter<EventListParentAdapter.MyViewHolder> {

    //private List<Movie> moviesList;

    private EventInformation eventInformation;
    private Activity activity;

    public EventListParentAdapter(EventInformation eventInformation,Activity activity) {
        this.eventInformation = eventInformation;
        this.activity = activity;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.event_list_parent_item, parent, false);

        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        EventDates eventDates = eventInformation.getEventsDatesList().get(position);
        holder.event_list_parent_date.setText(eventDates.getDate());

        LinearLayoutManager hs_linearLayout = new LinearLayoutManager(this.activity, LinearLayoutManager.VERTICAL, false);
        holder.event_recycler_view_child.setLayoutManager(hs_linearLayout);
        holder.event_recycler_view_child.setHasFixedSize(true);
        EventListChildAdapter eventListChildAdapter = new EventListChildAdapter(this.activity,eventInformation.getEventsDatesList().get(position).getEventsArrayList());
        holder.event_recycler_view_child.setAdapter(eventListChildAdapter);

    }

    @Override
    public int getItemCount() {
        return eventInformation.getEventsDatesList().size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        public TextView event_list_parent_date;
        public RecyclerView event_recycler_view_child;

        public MyViewHolder(View view) {
            super(view);
            event_list_parent_date = (TextView) view.findViewById(R.id.event_list_parent_date);
            event_recycler_view_child = (RecyclerView)view.findViewById(R.id.event_recycler_view_child);
        }
    }
}
/******************************************************************************//
6.copy EventListChildAdapter class , it is used to child data

public class EventListChildAdapter extends RecyclerView.Adapter<EventListChildAdapter.MyViewHolder> {

    //private List<Movie> moviesList;

    private EventInformation eventInformation;
    private ArrayList<Events> eventsArrayList;
    private Activity activity;

    public EventListChildAdapter(Activity activity,ArrayList<Events> eventsArrayList) {
        this.eventsArrayList = eventsArrayList;
        this.activity = activity;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.event_list_child_item, parent, false);
        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder,final int position) {
        Events events = eventsArrayList.get(position);
        holder.event_list_event_name.setText(events.getEventName());
        holder.event_list_event_name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d("event name=",eventsArrayList.get(position).getEventName());
            }
        });



    }

    @Override
    public int getItemCount() {
        return eventsArrayList.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        public TextView event_list_event_name;


        public MyViewHolder(View view) {
            super(view);
            event_list_event_name = (TextView) view.findViewById(R.id.event_list_event_name);

        }
    }
}


/**************************************************************************************/


Keywords: inner recycler view, nested recycler view , recyclerview within recyclerview















Saturday, 24 September 2016

How to create SharedPreferences and How to remove SharedPreferences in Android

Shared Preferences:
Shared Preferences allow you to save and retrieve data in the form of key,value pair.
It can be used to save user login information inside app rather than calling server every time when user open app.
Data saved using shared preferences are persisted in app even after closing app. we can manually delete shared preferences or it will be deleted automatically when app is uninstalled.

syntax : 
SharedPreferences sharedPreferences = getSharedPreferences("nameOfTheSharedPref",Context.MODE_PRIVATE);

Context.MODE_PRIVATE is used when you want your data only read by your app. this data is not shared with other app.

Below code shows how To create shared preferences 

//define pref name
public static final String UserAccountInfo = "myPrefs";
//define keys
public static final String UserName = "nameOfUser";
public static final String UserMobileNumber = "mobileNumberOfUser";
//define values
String userName = "manoj";
String userMobileNumber = "1234567890";
//create an instance of shared preferences with a name called UserAccountInfo
//Context.MODE_PRIVATE is used when you want your data only read by your app.
SharedPreferences sharedPreferences = getSharedPreferences(UserAccountInfo,Context.MODE_PRIVATE);
//get instance of editor which is used to save data in key value pairs
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(UserName, userName);
editor.putString(UserMobileNumber, userMobileNumber);
//commit is important, which actually saves your preferences
editor.commit();


Below code shows how to delete/remove shared preferences

//get the shared preference which you want to delete
SharedPreferences sharedPreferences = getSharedPreferences(RegisterOtpScreenActivity.UserAccountInfo, Context.MODE_PRIVATE);
//remove preferences one by one
sharedPreferences.edit().remove(RegisterOtpScreenActivity.UserName).commit();
sharedPreferences.edit().remove(RegisterOtpScreenActivity.UserMobileNumber).commit();
//commit your changes
sharedPreferences.edit().clear().commit();

Saturday, 17 September 2016

How to send Firebase Push Notification from HTTP server using java

Firebase HTTP server side code using java 


hello all

Before going to code , go through this link which will give you the format of the message as json that we are going to send as firebase push notification.

I am going to send below format json as push notification
 
 {
    "to" : "token which is received in android or ios app",
    "notification" : {
      "body" : "great match!",
      "title" : "Portugal vs. Denmark",
      "icon" : "myicon"
    },
    "data" : {
      "Nick" : "Mario",
      "Room" : "PortugalVSDenmark"
    }
  }

************************************************************

Now lets start coding :)

//import necessary packages  
import java.io.DataOutputStream;
import java.net.URL;
import java.util.HashMap;
import javax.net.ssl.HttpsURLConnection;
import org.json.simple.JSONObject;

public class Fcmtest {
/**
* @param args
*/
public static void main(String[] args) {
HttpsURLConnection con = null;
//FIREBASE_SERVER_KEY is nothing but server key that you got while creating firebase project in fcm
String FIREBASE_SERVER_KEY ="xxxxxxxxxxxxxxxx";
HashMap<String, Object> data = new HashMap<String, Object>();
data.put("Nick", "Mario!");
data.put("Room", "PortugalVSDenmark");
JSONObject dataJsonObject = new JSONObject();
dataJsonObject.put("hello", "world");
dataJsonObject.put("marco", "polo");
JSONObject titleInfo = new JSONObject();
titleInfo.put("body","great match!");
titleInfo.put("icon","myicon");
titleInfo.put("title", "Portugal vs. Denmark");
JSONObject finalJsonMessage= new JSONObject();
finalJsonMessage.put("notification", titleInfo);
finalJsonMessage.put("data", dataJsonObject);
//replace xxxxxxxx with token that you got when your app run first time means when your device registered to receive fcm from firebase
finalJsonMessage.put("to", "xxxxxxxxxxxxxxxxxxxxxxxxxxxx");
try{
String url = "https://fcm.googleapis.com/fcm/send";
URL obj = new URL(url);
con = (HttpsURLConnection) obj.openConnection();
con.setRequestMethod("POST");
// Set POST headers
con.setRequestProperty("Authorization", "key="+FIREBASE_SERVER_KEY);
con.setRequestProperty("Content-Type", "application/json");
// Send POST body
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(finalJsonMessage.toJSONString());
wr.flush();
wr.close();
con.getResponseCode();
}
catch(Exception e){
e.printStackTrace();
}
}
}

Thank you
mithun

How to solve Access restriction on jdk1.7/jre/lib/rt.jar in eclipse

Access restriction on jdk1.7/jre/lib/rt.jar

how to solve error in eclipse, follow the step

1.right click on your project, select properties.You will get a pop up window.

2.now select the java build path from the left list of the window.

3.now select the libraries tab in the window.

4.select existing jre library and remove it.

5.now select add library. now you will get a pop up window, select JRE system library from the list, 
click next
.
6.now select alternate JRE radio button. now dropdown will be enable. now select installed JRE. now your issue will be cleared.

Thank you
mithun

Thursday, 15 September 2016

Firebase Cloud Messaging FCM on Android device

Steps to integrate Firebase Cloud Messaging FCM with android.



1.open firebase.google.com
------------------------------------------------------
2.click on "go to console" which will be displayed on top right of the screen
------------------------------------------------------
3.now link will be directed to https://console.firebase.google.com/
------------------------------------------------------
4.click on create new project
------------------------------------------------------
5.now a pop up will come, asking to you to enter the project name and country. you can give any name. no restriction to the app name. enter the name of your country.
------------------------------------------------------
6.create project
------------------------------------------------------
7.click on firebase to your app(for android)
------------------------------------------------------
8.copy application id from(your android project which you want to integrate FCM) your app level gradle file and paste it to package name field in firebase. In the same package firebase(related) service classes should present.
------------------------------------------------------
9.copy debug key sha1 and paste it to debug key field in firebase.
Note: use this command to get sha1 key from windows
installed java path.....jdk/bin>keytool -list -v -keystore c:\users\systemname\.android\debug.keystore -alias androiddebugkey -storepass android -keypass android
note down sha1 key and paste it.
------------------------------------------------------
10.now click add app, now google-services.json file will be downloaded. paste this file in app directory.
------------------------------------------------------
11.open your project level grade file. add this - classpath 'com.google.gms:google-services:3.0.0' line in dependencies
------------------------------------------------------
12.open app level gradle file , paste this line - apply plugin: 'com.google.gms.google-services' at the bottom of the file.
------------------------------------------------------
13.add following lines in the app level gradle file.
compile 'com.google.firebase:firebase-messaging:9.4.0'
    compile 'com.google.firebase:firebase-auth:9.4.0'
    compile 'com.google.firebase:firebase-core:9.4.0'
    compile 'com.firebase:firebase-client-android:2.5.2+'
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
Note: always add updated dependencies.(https://firebase.google.com/docs/android/setup)
------------------------------------------------------
14.add FirebaseInstanceIDService.java file
Note: change ip address in the below file

import android.util.Log;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
import java.io.IOException;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;

public class FirebaseInstanceIDService extends FirebaseInstanceIdService {

    @Override
    public void onTokenRefresh() {
        String token = FirebaseInstanceId.getInstance().getToken();
        Log.d("token refresh =",token);
        registerToken(token);
    }
    private void registerToken(String token) {
        OkHttpClient client = new OkHttpClient();
        RequestBody body = new FormBody.Builder()
                .add("Token",token)
                .build();

        Request request = new Request.Builder()
                .url("http://your-ip-address/fcm/register.php")
                .post(body)
                .build();

        try {
            client.newCall(request).execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
------------------------------------------------------
15.now add FirebaseMessagingService.java

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import com.google.firebase.messaging.RemoteMessage;

public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService{

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.d("msg=",remoteMessage.getNotification().getBody());
        showNotification(remoteMessage.getData().get("message"),remoteMessage.getNotification().getTitle());
    }

    private void showNotification(String message,String title) {
        Log.d("wht is msg=",message);
        Intent i = new Intent(this,MainActivity.class);
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent pendingIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setAutoCancel(true)
                .setContentTitle(title)
                .setContentText(message)
                .setSmallIcon(R.drawable.common_google_signin_btn_icon_dark)
                .setContentIntent(pendingIntent);

        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        manager.notify(0,builder.build());
    }
}
------------------------------------------------------
16.add the new two classes into android manifest file.(they are services , so service tags must be used to define them)
Note:this is how your manifest file look like this

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="fcm.calcify.com.fcmexampple">
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service
            android:name=".FirebaseMessagingService"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>
        <service
            android:name=".FirebaseInstanceIDService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
            </intent-filter>
        </service>
    </application>
</manifest>

------------------------------------------------------

17.app level gradle file must look like this

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.0"

    defaultConfig {
        applicationId "fcm.calcify.com.fcmexampple"
        minSdkVersion 23
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.google.firebase:firebase-messaging:9.4.0'
    compile 'com.google.firebase:firebase-auth:9.4.0'
    compile 'com.google.firebase:firebase-core:9.4.0'
    compile 'com.firebase:firebase-client-android:2.5.2+'
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
}
apply plugin: 'com.google.gms.google-services'

------------------------------------------------------

18. project level gradle file

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'com.google.gms:google-services:3.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
---------------------------------------------
19.run the android project. copy the token from the console. now it is very important to note that you get token only once(first run). if you didnt copy token file. uninstall app  clean and build it now note down token.
------------------------------------------------------
20.now open this link https://console.firebase.google.com/. if you are logged in, you will see your project created in firebase.
------------------------------------------------------
21.click on your project. now select notification from the list for left of the screen(scroll down if you cant see notification link).
------------------------------------------------------
22.now click on new message. enter message text and label. select delivery date as "send now".
------------------------------------------------------
23. select your app. now select target as single device.
------------------------------------------------------
24. after selecting single device , you will be asked to enter FCM registration token. here enter your token.
------------------------------------------------------

Wednesday, 7 September 2016

when to use try catch over throws key word in java

hello all
you should be careful while using throws keyword in method declaration. if you do so then the exception that may thrown from your method may go unnoticed. so it is good to use try catch for a piece of code and handle the exception.

class Example
{
   public void method()throws Exception
      {
   //the exception may come here , but we cant notice as we have declared method as throws        //exception.
     //so use try catch here.
      }
}

//or you can have another choice, use try catch where you call method

Example e = new Example();
try{
e.method
}
catch(Exception e)
{
 //handle here
}