phonegap app loads first page upon screen orientation change - android

i am developing an android app using phonegap. i have multiple pages in the app and a single activity. whenever i change the orientation of the device, no matter which page i am on, the app loads the first page which is shown when the app is launched. i assumed it was because i had not overriden the onResume() method in the activity, but even that failed to solve the problem.
EDIT: This issue does not arise if the app is paused and the resumed.
My activity:
public class MainScreen extends DroidGap {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/landing.html");
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
}
EDIT: Added Manifest file
My Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.me.code"
android:versionCode="5"
android:versionName="1.4" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.miniorange.authenticator.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.miniorange.authenticator.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.miniorange.authenticator.MainActivity"
android:label="#string/app_name" >
</activity>
<activity android:name="com.miniorange.authenticator.MainScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.plugin.gcm.PushHandlerActivity"/>
<receiver android:name="com.plugin.gcm.CordovaGCMBroadcastReceiver" 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.me.code" />
</intent-filter>
</receiver>
<service android:name="com.plugin.gcm.GCMIntentService" />
</application>
</manifest>
what may be the solution to this problem?

sorry ... ( answering it late :D )
I had this problem with my app :
When I change the orientation, activity reloads ...
And I found this solution :
add this attribute to your <activity> tags :
android:configChanges="orientation"
suggestion ... use this insted (better) :
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
==========================================
information about solution :
what is the reason .. (?)
It'll say to application that you want to handle this changes (orientation, keyboardHidden, keyboard, screenSize, locale, etc.) yourself.

Related

Why Android App - Re-started when the application stopped form the Android Studio?

I am new to Android Development and I am developing an application to scan barcode using google vision API. In the application, I have three screens Splash Screen, Main Screen with two fragments (Scan & History) and Scanned Result. From the scan fragment, I am opening an activity called "ScannedResult" as soon as application scanned the barcode to show the result.
Now the problem is when I run the application from the Android Studio to the device.
[Scenario# 0] (From the Main activity screen app stopping that is the correct case)
Run the app
Splash Screen -> Main Screen
Shows scan fragment and run successful flow
Now, STOP the application from the Android Studio.
Application stopped
[Scenario# 1] (But from ScannedResult activity app stops and start again why?)
Run the app
Splash Screen -> Main Screen
Shows scan fragment and run successful flow
Now, Scan a Bar or QR Code then open ScannedResult (activity).
Now, STOP the application from the Android Studio.
Application stopped and show Black Screen
Application STARTED again and shows the Main Screen (Why it is starting again? I want to stop the application in this case).
Here I am suspecting something is wrong. Ideally, it must be stopped. Please help to identify where I am making mistake in the application.
Here is the Manifest.xml file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp.powertools.barcodescan">
<application
android:allowBackup="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".CreatePaypalUrl"
android:parentActivityName=".MainActivity"></activity>
<activity
android:name=".CreateVcardForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateLocationForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateWifiForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateEventForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateSmsForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateEmailForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateTelephoneForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateWebsiteForm"
android:parentActivityName=".MainActivity" />
<activity android:name=".Main2Activity" />
<activity
android:name=".GenerateQrCode"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateTextForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".ScannedResult"
android:parentActivityName=".MainActivity" />
<activity
android:name=".SplashScreen"
android:label="#string/app_name" android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:theme="#style/AppTheme.NoActionBar" />
<meta-data
android:name="com.google.android.gms.vision.DEPENDENCIES"
android:value="barcode" />
</application>
<uses-feature android:name="android.hardware.camera.front" android:required="false" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</manifest>
Scan.java file
barcodeDetector.setProcessor(new Detector.Processor<Barcode>() {
#Override
public void release() {
}
#Override
public void receiveDetections(Detector.Detections<Barcode> detections) {
final SparseArray<Barcode> qrCodes = detections.getDetectedItems();
if (qrCodes.size() > 0) {
if (isScanned == false) {
barcodeDetector.release();
isScanned = true;
String dataType = getBarcodeType(qrCodes.valueAt(0));
String dataValue = qrCodes.valueAt(0).displayValue;
String rawValue = qrCodes.valueAt(0).rawValue;
Intent intentScannedResult = new Intent(getActivity(), ScannedResult.class);
intentScannedResult.putExtra("barcode_raw_value", rawValue);
intentScannedResult.putExtra("barcode_value", dataValue);
intentScannedResult.putExtra("barcode_type", dataType);
intentScannedResult.putExtra("is_scanner", "1");
startActivity(intentScannedResult);
}
}
}
});

Android onCreate not firing on new activity

Hi there I am trying to execute some code when I change to the next activity, but it does not seem to work. The Previous activity is a login page if the user is already logged in it goes straight to the new activity. But the onCreate does not seem to fire.
Main Activity
public class MainActivity extends AppCompatActivity {
private View mMainView;
private Meteor mMeteor;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("ACTIVITY");
Log.d("SimpleActivity","OnCreate Started");
if(MeteorSingleton.getInstance().isConnected()){
Log.d("Connection", "Connected");
}else{
Log.d("Connection", "Not Connected");
}
}
........
The strange thing is the setTitle works but none of the logs.
Here is some code from the previous login in page.
#Override
public void onConnect(boolean signedInAutomatically) {
Log.i("Connection", "Connected to host server");
if (mMeteor.isLoggedIn()) {
openMainScreen(mLoginFormView);
}
}
public void openMainScreen(View view) {
Intent dashboard = new Intent(getApplicationContext(), MainActivity.class);
startActivity(dashboard);
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="system.carproject.adam.ams">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<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=".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=".MainActivity"
android:label="Activity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps"></activity>
</application>
</manifest>
If someone could educate me on this would be great. Can seem to figure it out.
Thanks
You have created two LAUNCHER Activities and that's created two App Icon in your Device so if you think its open directly MainActvity then its possible if you click on second app icon in your device for same application . check your device .
first remove LAUNCHER mode from MainActvity in Android Manifest and then you have to add manual check in your login Activity onCreate() for login status and then startActvity() MainActivty if login status is true.
try removing the intent filter tag from activity tag of MainActivity in Manifest:-
<activity android:name=".MainActivity"
android:label="Activity"> </activity>

Android app doesn't launch the main activity and says app isnt installed

So im kinda new to android programming and i dont really know why i cant run the main activity when i have a permission tag under the activity. this is my code under the manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lab08b_awahla"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="com.example.DANGEROUS_ACTION" />
<permission
android:name="com.example.DANGEROUS_ACTION"
android:label="permission"
android:protectionLevel="dangerous" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.lab08b_awahla.MainActivity"
android:label="#string/app_name"
android:permission="com.example.DANGEROUS_ACTION" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.example.DANGEROUS_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
This is obvious. If you are providing a security tag for activity anyone who wants to launch this activity has to have such privilege. Home screen app doesn't have (even don't known) your permission tag so this is a problem.
According to the docs for the <activity> tag
android:permission
The name of a permission that clients must have to launch the activity or otherwise get it to respond to an intent. If a caller of startActivity() or startActivityForResult() has not been granted the specified permission, its intent will not be delivered to the activity.
This leads me to think that you misunderstand the use of this attribute.

Android parse.com Can't receive push notification

I can't receive push notifications, using parse.com service.
I used a quick guide trying to solve my problem. I was trying to use channel this specified name and "" as a channel name. Also i found Cannot receive push notifications in Android with trigger.io and parse.com
I succeed to send object to parse.com, and to subscribe for notifications (at least I can see my app in DataBrowser on parse.com)
public class ParseStarterProjectActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
PushService.subscribe(this, "push", TestParse.class);
PushService.setDefaultPushCallback(this, TestParse.class);
}
}
public class ParseApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, my_id, my_client_key);
}
}
public class TestParse extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.parse);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.parse.starter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name="ParseApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<activity
android:name=".ParseStarterProjectActivity"
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=".TestParse"
android:label="#string/app_name" />
</application>
</manifest>
Recently I've noticed LogCat errors:
02-21 18:17:45.381: ERROR/Trace(8952): error opening trace file: No such file or directory (2)
02-21 18:17:48.534: ERROR/com.parse.PushService(8888): unknown host
I really want to receive notifications. What am I doing wrong?
Parse employee here. In order to handle increased load on our push service, we increased the number of machines serving push.parse.com. Some ISPs started having issues when DNS resolution returned this many servers. Last Friday afternoon, we launched a custom DNS server which works around these issues with 3rd party DNS resolution. This should no longer be an issue.

BackButton quit the application

I'm experiencing a trouble on my app, my backButton quit the application.
My application is a SyncService, everything seems to be great in the Manifest, i check for one day with no response...
I already check if the launchmode change something, i test the 4 and nothing append...
If someone can have a look on the manifest, it would be great :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.smile.android.ldapsync" android:versionCode="12" android:versionName="1.5">
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><application android:icon="#drawable/icon" android:label="#string/app_name" android:debuggable="true" android:enabled="true" android:persistent="true">
<service android:name="com.smile.android.ldapsync.authenticator.LDAPAuthenticationService" android:exported="true" android:debuggable="true">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data android:name="android.accounts.AccountAuthenticator" android:resource="#xml/authenticator" />
</service>
<service android:name="com.smile.android.ldapsync.syncadapter.SyncService" android:exported="true" android:debuggable="true">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data android:name="android.content.SyncAdapter" android:resource="#xml/syncadapter" />
</service>
<activity android:name="com.smile.android.ldapsync.authenticator.LDAPAuthenticatorActivity" android:label="#string/ui_activity_title" android:excludeFromRecents="true">
android:excludeFromRecents="true"
<!--
No intent-filter here! This activity is only ever launched by
someone who explicitly knows the class name
-->
</activity>
</application>
<uses-sdk android:minSdkVersion="5" />
</manifest>
Thank you ;)
Did you tried overriding onBackPressed ?
#Override
public void onBackPressed() {
return;
}
if you press back button while on the "main" activity (the first one you launched aka the bottom of your activity stack) the OS understand this as "the user is done and won't be back anytime soon" opposed as "home" button which is understood as "maybe the user wants to check something else before resuming the app"
So, if you DO NOT want your app to "terminate" (an android app terminates only when the OS kills it, otherwise it will lurk in memory until recalled) you need to override the back button pressed callback
public void onBackPressed()
which the api doc describes as:
"Called when the activity has detected the user's press of the back key. The default implementation simply finishes the current activity, but you can override this to do whatever you want."
You might just ignore the event and absorb it like timo schloesser suggested or you can do whatever is most appropriated (like, launching another activity or killing services before leaving the screen)
EDIT: you might also want to check the "moveTaskToBack" method inherited from Activity class. I have never used it but it might be useful to your problem.

Categories

Resources