1

I am developing one Android application using jQuery Mobile and Phonegap. Now, when i am log in to the application, it will display me the search some employees. In this screen i want to handle the device back button. Currently if i am pressing the back button, it is logging out from the app. But, i want minimize the app. it means, it should not log out. Just we will send the app to the background(Something similar to facebook android app). I tried to handle this using the below code:

<script type="text/javascript">
            $(document).ready(function() {
document.addEventListener("backbutton", function(e) {
                    alert("ready");
                    navigator.app.exitApp();
                });
            });
        </script> 

Here is my manifest file:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.innominds.myspace"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="7"
    />

     <uses-permission android:name="android.permission.VIBRATE" />
<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_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.HARDWARE_TEST" />
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-permission android:name="android.permission.BROADCAST_STICKY" />

    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
             android:configChanges="orientation|keyboardHidden" android:screenOrientation="portrait">
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

But when i am pressing the back button, it is not displaying the alert also. I am using cordova 2.0 and jquery.mobile-1.1.1.js.

I have been got some help and reference from here and here.

Can anyone please help me..

Community
  • 1
  • 1
Arindam Mukherjee
  • 2,255
  • 11
  • 48
  • 83

3 Answers3

0
<a href="#" data-rel="back" data-transition="slide" data-direction="reverse">
   Back
</a>

And programatically :

$("#buttonId").attr('href','index.html');

You can also change button title and its action runtime.

Michal Klouda
  • 14,263
  • 7
  • 53
  • 77
Ved
  • 2,701
  • 2
  • 22
  • 30
0

If you assign target-SDK in your AndroidManifest.xml then please remove that entry and try it.

rpelluru
  • 231
  • 1
  • 8
  • Share your AndroidManifest.xml file – rpelluru Oct 03 '12 at 06:42
  • 1
    You have to write phonegap plugin to handle your requirement and refer link for more info : http://stackoverflow.com/questions/9412501/how-to-create-plugin-in-phonegap-to-run-the-application-in-background – rpelluru Oct 05 '12 at 10:37
0

you have missed to add cordova.js file path in your html page. Sometime this file will not be added automatically in html page so add this manually and try again.

If this not work remove android platform and add again and add all the plugins once again, build the project only for android and run your problem will definitely will be resolved.

Bhola Nath Mahto
  • 484
  • 5
  • 18