android device imei pass to another class
<p>I want to pass android device id or imei number but when i pass from one class to another then application crash.
But it work fine when i am call with in same class plz help i am new to android.</p>

<pre><code>package com.example.deviceid;


 import android.app.Activity;
 import android.content.Context;
 import android.os.Bundle;
 import android.provider.Settings.Secure;
 import android.telephony.TelephonyManager;
 import android.widget.Toast;

public class GetId extends Activity {
String deviceId;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

}

public String AndroidId(){
    TelephonyManager telephonyManager =   (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    String imei=telephonyManager.getDeviceId();
    return imei;
  }

}
</code></pre>

<p>It is main class in which i am call imei number.</p>

<pre><code>  package com.example.deviceid;

  import android.app.Activity;
  import android.content.Context;
  import android.os.Bundle;

  import android.telephony.TelephonyManager;
  import android.widget.Toast;

  public class ShowDeviceInfo extends Activity {
     GetId gi;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

   setContentView(R.layout.main);
  gi = new GetId();
  String imei = gi.AndroidId();
  Toast.makeText(this, imei, Toast.LENGTH_SHORT).show();

}
}
</code></pre>

<p>XML file
    
    </p>

<pre><code>&lt;uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" /&gt;

&lt;application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" &gt;
    &lt;activity
        android:name="com.example.deviceid.ShowDeviceInfo"
        android:label="@string/app_name" &gt;
        &lt;intent-filter&gt;
            &lt;action android:name="android.intent.action.MAIN" /&gt;

            &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
        &lt;/intent-filter&gt;
    &lt;/activity&gt;
    &lt;activity
        android:name="com.example.deviceid.GetId"
        android:label="@string/app_name" &gt;

    &lt;/activity&gt;
  &lt;/application&gt;
 &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
 &lt;/manifest&gt;
</code></pre>
