• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps maps crashed when open through my application

  1. Hi, i am developing an application which has functionality of locate us.
  2. When user clicks on locate us button user will redirected to a particular location that i want to show on google maps.
  3. This works fine, my application redirects to google maps application and it opens location which i want to show but when i click back button on maps it displays my welcome page and sometimes it shows me error that "Unfortunately maps stopped".
  4. I tried everything but unable to find what is the issue. Can anyone please help me.

  5. This is my Welcome.java Activity :

  6. package mainApplication;

  7. import java.io.File;
  8. import readFile.*;

  9. import java.io.FileOutputStream;
  10. import java.io.InputStream;
  11. import java.util.Locale;

  12. import logs.TraceLog;

  13. import android.app.ActionBar;
  14. import android.app.Activity;
  15. import android.content.Intent;
  16. import android.content.res.AssetManager;
  17. import android.net.Uri;
  18. import android.os.Build;
  19. import android.os.Bundle;
  20. import android.os.Environment;
  21. import android.os.StrictMode;
  22. import android.view.KeyEvent;
  23. import android.view.View;
  24. import android.view.View.OnClickListener;
  25. import android.widget.Button;
  26. import android.widget.ImageButton;
  27. import android.widget.Toast;

  28. import forbes.mPassbook.R;
  29. public class Welcome extends Activity
  30. {
  31. ImageButton LoginHere,RegisterNow,Locate_us;
  32. String uri ="https://www.google.co.in/maps/place...ai!3m1!1s0x3be7d1e96fffffff:0x5e96526f98c8e98";

  33. String file_Path;

  34. TraceLog tc =new TraceLog();

  35. @override
  36. protected void onCreate(Bundle savedInstanceState)
  37. {
  38. super.onCreate(savedInstanceState);
  39. setContentView(R.layout.activity_welcome);

  40. ActionBar bar=getActionBar();
  41. bar.hide();

  42. file_Path=Environment.getExternalStorageDirectory()+ "/Android/data/forbes.mPassbook/";

  43. if( Build.VERSION.SDK_INT >= 9)
  44. {
  45. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
  46. StrictMode.setThreadPolicy(policy);
  47. }

  48. File conf=new File(file_Path + "config.properties");
  49. if(!conf.exists())
  50. {
  51. copyFiles();
  52. }
  53. ReadConfig rc = new ReadConfig();


  54. /****************GIF code implementation***********************/
  55. /*ImageView img = (ImageView)findViewById(R.id.imageView2);
  56. img.setBackgroundResource(R.drawable.gifanim);

  57. // Get the background, which has been compiled to an AnimationDrawable object.
  58. AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();

  59. // Start the animation (looped playback by default).
  60. frameAnimation.start();*/

  61. LoginHere = (ImageButton)findViewById(R.id.image_user_login);
  62. RegisterNow = (ImageButton)findViewById(R.id.image_register);
  63. Locate_us =(ImageButton)findViewById(R.id.image_locateus);

  64. RegisterNow.setOnClickListener(new OnClickListener()
  65. {
  66. @override
  67. public void onClick(View arg0)
  68. {
  69. Intent i = new Intent(Welcome.this, Registration.class);

  70. // // Closing all the Activities
  71. // i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  72. //
  73. // // Add new Flag to start new Activity
  74. // i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

  75. i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  76. startActivity(i);
  77. finish();
  78. }
  79. });

  80. LoginHere.setOnClickListener(new OnClickListener()
  81. {
  82. @override
  83. public void onClick(View arg0)
  84. {
  85. File file_cust_id=new File(file_Path + "customer.properties");
  86. if(file_cust_id.exists())
  87. {
  88. Intent i = new Intent(Welcome.this, Login.class);
  89. i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  90. startActivity(i);
  91. finish();
  92. }
  93. else
  94. {
  95. Toast.makeText(getApplicationContext(),"Please Register First",Toast.LENGTH_LONG).show();
  96. }
  97. }
  98. });

  99. //Locate us button

  100. Locate_us.setOnClickListener(new OnClickListener()
  101. {
  102. @override
  103. public void onClick(View v)
  104. {
  105. try
  106. {
  107. Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
  108. Uri.parse("https://www.google.co.in/maps/place...!1s0x3be7d1e96fffffff:0x5e96526f98c8e98?hl=en"));
  109. startActivity(intent);

  110. // Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
  111. // intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
  112. // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  113. // startActivity(intent);
  114. // // finish();
  115. }
  116. catch(Exception ex)
  117. {
  118. Toast.makeText(getApplicationContext(),"Error In Google Maps",Toast.LENGTH_LONG).show();
  119. }
  120. }

  121. });
  122. }

  123. //Copy Property Files from Asset Folder to SD card on startup
  124. public void copyFiles()
  125. {
  126. try
  127. {
  128. File dataDirectory = new File(file_Path);
  129. // have the object build the directory structure, if needed.
  130. if(!dataDirectory.exists())
  131. dataDirectory.mkdirs();

  132. AssetManager am = getAssets();
  133. String[] list = am.list("");
  134. for (String s:list)
  135. {
  136. if (s.startsWith("config"))
  137. {
  138. InputStream inStream = am.open(s);
  139. int size = inStream.available();
  140. byte[] buffer = new byte[size];
  141. inStream.read(buffer);
  142. inStream.close();
  143. FileOutputStream fos = new FileOutputStream(file_Path + s);
  144. fos.write(buffer);
  145. fos.close();
  146. }
  147. }
  148. }
  149. catch (Exception ex)
  150. {
  151. tc.WriteToTransactionLog("Exception: Welcome.java copyFiles():- "+ex.toString());
  152. ex.printStackTrace();
  153. }
  154. }

  155. @override
  156. public boolean onKeyDown(int keyCode, KeyEvent event)
  157. {
  158. if ( keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)
  159. {
  160. onBackPressed();
  161. }
  162. return super.onKeyDown(keyCode, event);
  163. }

  164. @override
  165. public void onBackPressed()
  166. {
  167. try
  168. {
  169. //Success Register dialog box
  170. Exit e = new Exit(Welcome.this);
  171. e.show();
  172. e.setCanceledOnTouchOutside(false);
  173. }
  174. catch (Exception e)
  175. {
  176. // TODO Auto-generated catch block
  177. e.printStackTrace();
  178. }
  179. }

  180. public void onDestroy()
  181. {
  182. super.onDestroy();
  183. finish();
  184. }

  185. // public void onRestart()
  186. // {
  187. // super.onRestart();
  188. // startActivity(new Intent(this, Welcome.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
  189. // }
  190. }


  191. My Welcome.xml :

  192. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  193. xmlns:tools="http://schemas.android.com/tools"
  194. android:layout_width="match_parent"
  195. android:layout_height="match_parent"
  196. tools:context="forbes.welcome.Hdfc_welcome"
  197. android:background="@drawable/bbk_base_screen">

  198. - <ImageButton
  199. android:id="@+id/image_user_login"
  200. android:layout_width="wrap_content"
  201. android:layout_height="wrap_content"
  202. android:layout_alignParentLeft="true"
  203. android:layout_alignTop="@+id/image_register"
  204. android:src="@drawable/user_login" />

  205. <ImageButton

  206. android:id="@+id/image_register"
  207. android:layout_width="wrap_content"
  208. android:layout_height="wrap_content"
  209. android:layout_centerHorizontal="true"
  210. android:layout_centerVertical="true"
  211. android:src="@drawable/register" />

  212. <ImageButton
  213. android:id="@+id/image_locateus"
  214. android:layout_width="wrap_content"
  215. android:layout_height="wrap_content"
  216. android:layout_alignTop="@+id/image_register"
  217. android:layout_alignParentRight="true"
  218. android:src="@drawable/locate_us_icon" />

  219. <!-- <TextView
  220. android:id="@+id/text_hdfc"
  221. android:layout_width="wrap_content"
  222. android:layout_height="wrap_content"
  223. android:layout_alignLeft="@+id/text_welcome"
  224. android:layout_below="@+id/text_welcome"
  225. android:layout_marginLeft="20dp"
  226. android:textColor="#d4ccb9"
  227. android:textSize="24sp"
  228. android:textStyle="bold|italic"
  229. android:text="M-Passbook" /> -->

  230. <!-- <EditText
  231. android:id="@+id/editText_user"
  232. android:layout_width="wrap_content"
  233. android:layout_height="wrap_content"
  234. android:background="#d4ccb9"
  235. android:drawableLeft="@drawable/user_icon"
  236. android:layout_centerHorizontal="true"
  237. android:layout_below="@+id/text_hdfc"
  238. android:ems="10"
  239. android:maxLength="15"
  240. android:layout_marginTop="20dp"
  241. android:hint="@String/user_name" >
  242. </EditText>
  243. <EditText
  244. android:id="@+id/editText_password"
  245. android:layout_width="wrap_content"
  246. android:layout_height="wrap_content"
  247. android:background="#d4ccb9"
  248. android:drawableLeft="@drawable/key_icon"
  249. android:ems="10"
  250. android:maxLength="15"
  251. android:hint="@String/password"
  252. android:layout_centerHorizontal="true"
  253. android:layout_below="@+id/editText_user"
  254. android:layout_marginTop="20dp"
  255. android:layout_marginBottom="20dp"
  256. android:inputType="textPassword" />

  257. <ImageButton
  258. android:id="@+id/button_login"
  259. android:layout_width="45dp"
  260. android:layout_height="45dp"
  261. android:layout_alignTop="@+id/editText_user"
  262. android:layout_marginLeft="10dp"
  263. android:layout_marginTop="20dp"
  264. android:layout_toRightOf="@+id/editText_password"
  265. android:src="@drawable/unlock_icon" /> -->

  266. <TextView
  267. android:id="@+id/text_welcome"
  268. android:layout_width="wrap_content"
  269. android:layout_height="wrap_content"
  270. android:layout_below="@+id/image_user_login"
  271. android:layout_centerHorizontal="true"
  272. android:layout_marginTop="28dp"
  273. android:text="Welcome To mPassbook"
  274. android:textColor="#d4ccb9"
  275. android:textSize="24sp"
  276. android:textStyle="italic" />

  277. </RelativeLayout>
 
Back
Top Bottom