I'd like to start an activity every time the phone has an incoming call and, inside the activity, show some details about the number or accept / refuse the call.
The problem is that every time i receive a call the activity doesn't start.
Here is my code:
public class PhoneCallReceiver extends AriesMobileBroadcastReceiver {
#Override
public void onReceive(final Context context, Intent intent) {
super.onReceive(context, intent);
if(!preferences.getBoolean(Preferences.CALL_SHOW_CUSTOMER_INFOS, false))
return;
TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(new PhoneStateListener() {
public void onCallStateChanged(int state, final String incomingNumber){
switch(state){
case TelephonyManager.CALL_STATE_IDLE:
Log.d(TAG, "IDLE");
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.d(TAG, "OFFHOOK");
break;
case TelephonyManager.CALL_STATE_RINGING:
Log.d(TAG, "RINGING: " + incomingNumber);
final Intent intent = new Intent(context, PhoneCallActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(PhoneCallActivity.EXTRA_PHONE_NUMBER, incomingNumber);
new Thread() {
public void run() {
long now = AriesUtils.currentTimeStamp();
try {
Thread.sleep(500);
} catch(InterruptedException e) {}
now = AriesUtils.currentTimeStamp() - now;
Log.e(TAG, "ELAPSED TIME: " + now);
context.startActivity(intent);
}
}.start();
break;
}
}
}, PhoneStateListener.LISTEN_CALL_STATE);
}
the activity (which, actualy, does nothing ):
public class PhoneCallActivity extends AriesMobileActivity {
public static final String EXTRA_PHONE_NUMBER = "phone_number";
private TextView tvPhoneCallContact;
private TextView tvPhoneCallNumber;
private TextView tvPhoneCallSystem;
private ImageView imgPhoneCallStatus;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.e(TAG, "PHONE CALL ACTIVITY STARTED");
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
window.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
window.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
setContentView(R.layout.layout_phone_call);
Intent intent = getIntent();
if(!intent.hasExtra(EXTRA_PHONE_NUMBER)) {
finish();
return;
}
String phoneNumber = intent.getStringExtra(EXTRA_PHONE_NUMBER);
phoneNumber = phoneNumber.replace("+39", "").replace(" ", "");
CustomerContact[] contacts = new CustomerContact.Provider(context).findByPhoneNumber(phoneNumber);
if(contacts.length <= 0) {
finish();
return;
}
}
and the layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test1"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test2"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Answer" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Refuse" />
</LinearLayout>
So my requests are:
1- how do i start the activity when the phone rings?
2- how do i manage the respond/refuse button?
3- if this solution is impossible/not good/stupid is there any other way to show informations when a call is received? (for example some kind of notification)
thanks in advance
manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ngs.ariesmobile"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application
android:name=".AriesMobileApplication"
android:allowBackup="true"
android:icon="#drawable/app_logo"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo.Light.NoActionBar" >
<receiver android:name=".receivers.PhoneCallReceiver" >
<intent-filter >
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
<activity
android:name=".view.LoginActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".view.HomeActivity"
android:label="#string/app_name" />
<activity
android:name=".view.SignatureCaptureActivity"
android:configChanges="orientation|keyboard|screenSize"
android:label="#string/app_name"
android:screenOrientation="sensorLandscape" />
<activity
android:name=".view.SetupHomeActivity"
android:configChanges="orientation|keyboard|screenSize"
android:label="#string/app_name" />
<activity
android:name=".view.SetupApiActivity"
android:configChanges="orientation|keyboard|screenSize"
android:label="#string/app_name" />
<activity
android:name=".view.SetupLoginActivity"
android:configChanges="orientation|keyboard|screenSize"
android:label="#string/app_name" />
<activity
android:name=".view.SetupTechnicianActivity"
android:configChanges="orientation|keyboard|screenSize"
android:label="#string/app_name" />
<activity
android:name=".view.SettingsActivity"
android:configChanges="orientation|keyboard|screenSize"
android:label="#string/app_name" />
<activity
android:name=".view.SettingsPasswordActivity"
android:configChanges="orientation|keyboard|screenSize"
android:label="#string/app_name" />
<activity
android:name=".view.SettingsApiActivity"
android:configChanges="orientation|keyboard|screenSize"
android:label="#string/app_name" />
<activity
android:name=".view.SynchronizationActivity"
android:configChanges="orientation|keyboard|screenSize"
android:label="#string/app_name" />
<activity
android:name=".view.ReportCustomerActivity"
android:configChanges="orientation|keyboard|screenSize"
android:label="#string/app_name"
android:screenOrientation="sensorLandscape" />
<activity
android:name=".view.ReportInternalActivity"
android:configChanges="orientation|keyboard|screenSize"
android:label="#string/app_name"
android:screenOrientation="sensorLandscape" />
<activity
android:name=".view.ReportListActivity"
android:configChanges="orientation|keyboard|screenSize"
android:label="#string/app_name" />
<activity
android:name=".view.TicketListActivity"
android:configChanges="orientation|keyboard|screenSize"
android:label="#string/app_name" />
<activity
android:name=".view.PhoneCallActivity"
android:configChanges="orientation|keyboard|screenSize"
android:label="#string/app_name"
android:theme="#android:style/Theme.Translucent" />
<activity
android:name=".view.SystemActivity"
android:configChanges="orientation|keyboard|screenSize"
android:screenOrientation="landscape"
android:label="#string/app_name" />
<activity
android:name=".view.SystemListActivity"
android:configChanges="orientation|keyboard|screenSize"
android:label="#string/app_name" />
<activity
android:name=".view.ReportSummaryActivity"
android:configChanges="orientation|keyboard|screenSize"
android:screenOrientation="portrait"
android:label="#string/app_name" />
<activity
android:name=".view.ManualsListActivity"
android:configChanges="orientation|keyboard|screenSize"
android:label="#string/title_activity_manuals_list" >
</activity>
<activity
android:name=".view.SystemStoricalActivity"
android:configChanges="orientation|keyboard|screenSize"
android:label="#string/title_activity_system_storical" >
</activity>
<activity
android:name=".view.SystemTechnicalPartActivity"
android:configChanges="orientation|keyboard|screenSize"
android:label="#string/title_activity_system_technical_part" >
</activity>
<activity
android:name=".view.SystemConsActivity"
android:configChanges="orientation|keyboard|screenSize"
android:label="#string/title_activity_system_cons" >
</activity>
<activity
android:name=".view.SystemNoteActivity"
android:configChanges="orientation|keyboard|screenSize"
android:label="#string/title_activity_system_note" >
</activity>
<activity
android:name=".view.SystemSupervisionActivity"
android:configChanges="orientation|screenSize"
android:label="#string/title_activity_system_supervision" >
</activity>
<activity
android:name=".view.CalendarActivity"
android:configChanges="orientation|screenSize"
android:screenOrientation="landscape"
android:label="#string/title_activity_calendar" >
</activity>
<activity
android:name=".view.ReportHoursActivity"
android:label="#string/title_activity_report_hours" >
</activity>
<!--- <activity
android:name="ngs.ariesmobile.view.ReportHoursActivity"
android:label="#string/title_activity_report_hours" >
</activity> -->
</application>
</manifest>
Related
One of the requirements in the app that I am developing is "show something on the screen on event." Basically, I made a background service and in that, I catch the screen on intent and pass it to a BroadcastReceiver. Then, in the receiver, I open an activity and "show something". However, on Android 7-8. I think the background service get killed over a night because the next day my service is not catching anything and my receiver is not receiving. I even ask for the
<uses-permission
android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
permission, and override it, but the service still gets killed. You can find my Service class, Receiver class, and manifest below.
Service class
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
public class Services extends Service {
private static final String TAG = "Services";
private BroadcastReceiver sReceiver;
public static final String ALARM_ALERT_ACTION = "com.android.deskclock.ALARM_ALERT";
public IBinder onBind(Intent arg) {
return null;
}
public int onStartCommand(Intent intent, int flag, int startIs) {
Log.i(TAG, "onStartCommand: " + this.toString() + " sReceiver = " + sReceiver);
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction(ALARM_ALERT_ACTION);
sReceiver = new Receivers(new Handler());
registerReceiver(sReceiver, filter);
if(intent != null){
LUtil.appendToLogs("Service onStartCommand " + intent.getAction() + " intent catched.");
}
return START_STICKY;
}
#Override
public void onDestroy() {
super.onDestroy();
unregisterReceiver(sReceiver);
}
}
Receiver class:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.os.Handler;
import android.util.Log;
import com.mytoz.app.object.CommercialData;
import java.io.File;
import java.util.ArrayList;
public class Receivers extends BroadcastReceiver {
private static final String TAG = "Receivers";
private final Handler handler;
public Receivers(Handler handler) {
this.handler = handler;
}
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "onReceive: id = " + this.toString());
Log.i(TAG, "intent.getAction() " + intent.getAction());
LUtil.appendToLogs("onReceive " + intent.getAction() + " intent passed to receiver.");
if(LUtil.isPowerOff){
LUtil.isPowerOff = false;
return;
}
if (intent.getAction() != null) {
if(intent.getAction().equals(Services.ALARM_ALERT_ACTION)){
LUtil.lastAlarmAlert = System.currentTimeMillis();
Log.i(TAG, "onReceive: LUtil.lastAlarmAlert = " + LUtil.lastAlarmAlert);
return;
}
if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
final int mode = am.getMode();
if (AudioManager.MODE_IN_CALL == mode) {
Log.i(TAG, "onReceive: in call");
// device is in a telephony call
} else if (AudioManager.MODE_IN_COMMUNICATION == mode) {
Log.i(TAG, "onReceive: commuunication");
// device is in communiation mode, i.e. in a VoIP or video call
} else if (AudioManager.MODE_RINGTONE == mode) {
Log.i(TAG, "onReceive: ringtone");
// device is in ringing mode, some incoming is being signalled
} else {
// SHOW SOMETHING
}
} else {
}
}
}
}
My Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission
android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<application xmlns:tools="http://schemas.android.com/tools"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#mipmap/app_logo"
android:label="#string/app_name"
android:largeHeap="true"
android:roundIcon="#mipmap/app_logo"
android:screenOrientation="portrait"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:replace="android:hardwareAccelerated"
android:name=".Mytoz">
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<meta-data
android:name="firebase_crashlytics_collection_enabled"
android:value="false" />
<meta-data
android:name="preloaded_fonts"
android:resource="#array/preloaded_fonts" />
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
<service android:name=".Services" />
<service
android:exported="false"
android:name=".FirebaseJobService">
<intent-filter>
<action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE"/>
</intent-filter>
</service>
<service
android:name=".PushHandleService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<receiver
android:enabled="true"
android:exported="true"
android:name=".BootCompletedReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<receiver
android:enabled="true"
android:exported="true"
android:name=".UpdateReceiver">
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
</receiver>
<activity
android:name=".SplashScreen"
android:theme="#style/SplashTheme" android:configChanges="orientation"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".networking.CrashReportHandle" />
<activity android:name=".LoginActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".MainActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".CommercialVideo" android:taskAffinity=".CommercialVideo" android:excludeFromRecents="true" android:configChanges="orientation"
android:screenOrientation="portrait" android:launchMode="singleTop"/>
<activity android:name=".ShopActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".InterestActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity
android:name=".SignUpActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateVisible|adjustResize" />
<activity android:name=".MyAdsActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".SignUpThirdActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".SignUpSecondActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".RegisterActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".SettingsFirstActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".SettingsSecondActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".SettingsThirdActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".ItemDetailActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".CheckoutActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".DeliveryActivity" android:configChanges="orientation"
android:screenOrientation="portrait" android:windowSoftInputMode="stateVisible|adjustResize" />
<activity
android:configChanges="orientation"
android:screenOrientation="portrait"
android:name="com.braintreepayments.api.BraintreeBrowserSwitchActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="${applicationId}.braintree" />
</intent-filter>
</activity>
<activity android:name=".PaymentActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".CreditCardActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".OfferActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".ConfirmationActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".AdsSecondActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".CustomAdsVideoActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".OrderActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".OrderDetailsActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity
android:name=".SmartyAdsActivity"
android:configChanges="orientation|keyboardHidden|screenSize" />
</application>
</manifest>
AndroidManifest.java
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bidnextjob.bidnextjob">
<!-- Lat lon fetching permission by GPSTracker class start and also use for google map -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.bidnextjob.bidnextjob.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Allows access to the flashlight -->
<permission
android:name="android.permission.FLASHLIGHT"
android:permissionGroup="android.permission-group.HARDWARE_CONTROLS"
android:protectionLevel="normal" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/MyTheme">
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" />
<activity android:name=".LoginActivity" />
<activity android:name=".RegisterActivity" />
<activity
android:name=".HomeActivity"
android:windowSoftInputMode="stateAlwaysHidden" />
<activity android:name=".FilterActivity" />
<activity android:name=".JobDetailsActivity" />
<activity android:name=".EditProfileActivity"
android:windowSoftInputMode="stateAlwaysHidden"/>
<activity
android:name=".ChatActivity"
android:windowSoftInputMode="stateAlwaysHidden" />
<activity android:name=".AboutUsActivity" />
<activity android:name=".HelpActivity" />
<activity android:name=".ReviewActivity" />
<activity
android:name=".CommentActivity"
android:windowSoftInputMode="stateAlwaysHidden" />
<activity android:name=".ForgetPasswordActivity" />
<activity
android:name=".PlaceBidActivity"
android:windowSoftInputMode="stateAlwaysHidden" />
<activity
android:name=".EditBidActivity"
android:windowSoftInputMode="stateAlwaysHidden" />
<activity android:name=".JobDetails1Activity" />
<activity android:name=".NotificationsActivity" />
<activity android:name=".ChooseCategoryActivity" />
<activity android:name=".BidDetailsActivity" />
<activity android:name=".EditAddressActivity" />
<activity android:name=".UpdateProfileActivity" />
<activity android:name=".GiveRatingActivity" />
<activity android:name=".ArchiveActivity"/>
<activity android:name=".AutoCompleteAddress"/>
<activity
android:name=".SocialLoginActivity"
android:label=".SocialLoginActivity" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="<some api key>" />
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name"
android:theme="#android:style/Theme.Translucent.NoTitleBar" />
<service android:name="utilities.gcm.GcmIntentService" />
<receiver
android:name="utilities.gcm.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.bidnextjob.bidnextjob" />
</intent-filter>
</receiver>
</application>
</manifest>
I'm accessing a Pojo class having static method for returning value. When I access this static method in my Splash Screen class(Launcher page), I get a NoClassDefFoundError for that Pojo class. How to avoid this exception without making the method non-static?
LogCat
FATAL EXCEPTION: main
Process: com.bidnextjob.bidnextjob, PID: 30515
java.lang.NoClassDefFoundError: shared_pref.SharedStorage
at com.bidnextjob.bidnextjob.SplashActivity.onCreate(SplashActivity.java:21)
at android.app.Activity.performCreate(Activity.java:5280)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2322)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2410)
at android.app.ActivityThread.access$800(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5388)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:655)
at dalvik.system.NativeStart.main(Native Method)
Pojo class
package shared_pref;
public class SharedStorage {
static SharedPreferences preference;
private static String prefData="ExampleStructApp";
public static String UserId= "UserId";
public static String UserType= "UserType";
public static void setValue(Context context,String key,String data){
preference = context.getSharedPreferences(prefData, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preference.edit();
editor.putString(key,data);
editor.commit();
}
public static String getValue(Context context,String key){
preference = context.getSharedPreferences(prefData, Context.MODE_PRIVATE);
String id = preference.getString(key,"");
return id;
}
public static void resetValue(Context context){
preference = context.getSharedPreferences(prefData, Context.MODE_PRIVATE);
preference.edit().clear().commit();
}
}
Splash Screen class
public class SplashActivity extends AppCompatActivity {
private String user_id = "";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
// Here I get NoClassDefFoundError
user_id = SharedStorage.getValue(getApplicationContext(),"UserId");
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
if(user_id != null && !user_id.isEmpty()){
startActivity(new Intent(SplashActivity.this, HomeActivity.class));
finish();
}else{
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
}
}
}, 3000);
}
}
This is caused when there is a class file that your code depends on and it is present at compile time but not found at runtime. Look for differences in your build time and runtime classpaths.
Before my application was working fine. I just created a new class (within the same package) and also declared it in the manifest, still I get a ActivityNotFoundException and sometimes NoClassDefFoundException.
TestActivity.java
public class TestActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.order_summary);
}
}
Activity_NewOrder.java
public class Activity_NewOrder extends Activity
try {
//Also tried Intent intent = new Intent(Activity_NewOrder.this, TestActivity.class);
Intent intent = new Intent(getApplicationContext(), TestActivity.class);
startActivity(intent);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mypackage">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".Activities.Activity_OrderSummaryNew"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape" />
<activity
android:name=".Activities.Activity_Login"
android:configChanges="orientation"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Activities.Activity_Orders"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape" />
<activity
android:name=".Activities.Activity_NewOrder"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape" />
<activity
android:name=".Activities.Activity_OrderHistory"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape" />
<activity android:name=".Activities.TestActivity" />
</application>
</manifest>
I have this WelcomeActivity where I programmed 4 ImageButtons to launch another activities.
This is my code:
public class WelcomeScreen extends Activity {
ImageButton completeprofile;
ImageButton gotoportfolio;
ImageButton findfriends;
ImageButton readnews;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome_activity);
completeprofile = (ImageButton) findViewById(R.id.completeprofile);
gotoportfolio = (ImageButton) findViewById(R.id.gotoportfolio);
findfriends = (ImageButton) findViewById(R.id.findfriends);
readnews = (ImageButton) findViewById(R.id.readnews);
completeprofile.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(WelcomeScreen.this, LoginMember.class);
startActivity(i);
}
});
gotoportfolio.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(WelcomeScreen.this, MainActivity.class);
startActivity(i);
}
});
findfriends.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(WelcomeScreen.this, MainActivity.class);
startActivity(i);
}
});
readnews.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(WelcomeScreen.this, RegisterMember.class);
startActivity(i);
}
});
}}
Problem is, they actually behave like buttons when I click them, but no activity is launched, this is the layout declaration:
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="70dp"
android:layout_marginLeft="105dp">
<ImageButton
android:layout_width="55dp"
android:layout_height="55dp"
android:id="#+id/completeprofile"
android:src="#drawable/completeprofile"
android:layout_marginLeft="75dp"
android:contentDescription="completeprofile" />
<ImageButton
android:layout_width="55dp"
android:layout_height="55dp"
android:id="#+id/gotoportfolio"
android:src="#drawable/gotoportfolio"
android:layout_marginLeft="65dp" />
<ImageButton
android:layout_width="55dp"
android:layout_height="55dp"
android:id="#+id/findfriends"
android:src="#drawable/findfriends"
android:layout_marginLeft="65dp" />
<ImageButton
android:layout_width="55dp"
android:layout_height="55dp"
android:id="#+id/readnews"
android:src="#drawable/readnews"
android:layout_marginLeft="65dp" />
</LinearLayout>
Why is this happening? Maybe the intent launch has some issue?
Any ideas?
thanks in advance!
EDIT
Here's the manifest:
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="21"
tools:overrideLibrary="android.support.multidex" />
<supports-screens
android:largeScreens="true"
android:normalScreens="false"
android:requiresSmallestWidthDp="600"
android:smallScreens="false"
android:xlargeScreens="true" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
<!-- <uses-sdk /> -->
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#drawable/logo"
android:label="Shairlook"
android:theme="#style/AppTheme" >
<activity
android:name="com.kkoci.shairlook.SplashScreen"
android:configChanges="orientation"
android:label="Shairlook"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.kkoci.shairlook.MemberActivity"
android:configChanges="orientation"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.kkoci.shairlook.RegisterMember"
android:configChanges="orientation"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.kkoci.shairlook.LoginMember"
android:configChanges="orientation"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.kkoci.shairlook.WelcomeScreen"
android:configChanges="orientation"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.kkoci.shairlook.YoutubeVid"
android:configChanges="orientation"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.kkoci.shairlook.ProfileMember"
android:configChanges="orientation"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.kkoci.shairlook.PortfolioMember"
android:configChanges="orientation"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.kkoci.shairlook.ForgotPassActivity"
android:configChanges="orientation"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.kkoci.shairlook.MainActivity"
android:configChanges="orientation"
android:label="Shairlook"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.kkoci.shairlook.WebActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo" >
</activity>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
</application>
#override won't cause problem. It's quite weird if activities are added in manifest and present in same pkg.
can you please add debug Log in onClick(), this will narrow down the problem whether problem is really with callback or not.
try android:clickable="true"/android:focusable="true"/ android:focusableInTouchMode="true" as additional attributes for ImageButton
Hope this helps!
You should remove the '#Override' from above each onClick method, they are not needed and this may be causing you an issue.
package com.netvariant.zain.activity;
public class StoreMapActivity extends SherlockFragmentActivity {
private GoogleMap googleMap;
String longitude="0";
String latitude="0";
String title="";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
Bundle extras = getIntent().getExtras();
longitude = extras.getString("longitude");
latitude = extras.getString("lattitude");
title= extras.getString("name");
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
private void initilizeMap() {
if (googleMap == null) {
double savedLat = Double.parseDouble(latitude);
double savedLng =Double.parseDouble(longitude);
LatLng cameraLatLng = new LatLng(savedLat, savedLng);
googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.map)).getMap();
googleMap.addMarker(new MarkerOptions()
.position(new LatLng( Float.parseFloat(latitude), Float.parseFloat(longitude))).title("Marker")
.title(title));
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(cameraLatLng, 17));
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
protected void onResume() {
super.onResume();
initilizeMap();
}
}
This is my map class, on samsung s4 4.2.2 it crashes. I use google play services froyo for it.
The layout is simple, its a fragment. Unfortunately, I dont have s4 myself to detect whats happening. Its being reported by someone trying it on s4 that its crashing. Any helps would be thankful.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="#+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
my manifest file and hope it helps.....
<uses-permission android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.PHONE_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_USER_DICTIONARY" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<application
android:name="com.netvariant.zain.android.ZainApp"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.netvariant.zain.activity.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.netvariant.zain.activity.RegionalStoresActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.RegionalStoresMeActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.UsageActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.StoresActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.PackagePlanActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.CategoriesActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.LoadingActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.LoginActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.LoginAuthenticationActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.SlidingMenuActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.CategoriesNewsActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.ArticlesActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.ArticlesNewsActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.StoreMapActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.PostPaidMenuVoiceActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.PrePaidMenuVoiceActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.PrePaidMenuDataActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.PostPaidMenuDataActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.BillsActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.ExtrasActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.BillsAmountActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.CallDetailsInnerActivity"
android:screenOrientation="portrait" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyD6geBmLw7N6gkDy1zCg7Y4yMtf_QnAOMs" />
</application>
Add the following,
< meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" >
< /meta-data>
in your manifest file immediately below the first meta-data tag(where you have placed your google api key)