After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more
here .
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser .
Apps maps crashed when open through my application
Hi, i am developing an application which has functionality of locate us.
When user clicks on locate us button user will redirected to a particular location that i want to show on google maps.
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".
I tried everything but unable to find what is the issue. Can anyone please help me.
This is my Welcome.java Activity :
package mainApplication;
import java.io.File;
import readFile.*;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Locale;
import logs.TraceLog;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.content.res.AssetManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.StrictMode;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;
import forbes.mPassbook.R;
public class Welcome extends Activity
{
ImageButton LoginHere,RegisterNow,Locate_us;
String uri ="https://www.google.co.in/maps/place...ai!3m1!1s0x3be7d1e96fffffff:0x5e96526f98c8e98 ";
String file_Path;
TraceLog tc =new TraceLog();
@override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
ActionBar bar=getActionBar();
bar.hide();
file_Path=Environment.getExternalStorageDirectory()+ "/Android/data/forbes.mPassbook/";
if( Build.VERSION.SDK_INT >= 9)
{
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
File conf=new File(file_Path + "config.properties");
if(!conf.exists())
{
copyFiles();
}
ReadConfig rc = new ReadConfig();
/****************GIF code implementation***********************/
/*ImageView img = (ImageView)findViewById(R.id.imageView2);
img.setBackgroundResource(R.drawable.gifanim);
// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
// Start the animation (looped playback by default).
frameAnimation.start();*/
LoginHere = (ImageButton)findViewById(R.id.image_user_login);
RegisterNow = (ImageButton)findViewById(R.id.image_register);
Locate_us =(ImageButton)findViewById(R.id.image_locateus);
RegisterNow.setOnClickListener(new OnClickListener()
{
@override
public void onClick(View arg0)
{
Intent i = new Intent(Welcome.this, Registration.class);
// // Closing all the Activities
// i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//
// // Add new Flag to start new Activity
// i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
finish();
}
});
LoginHere.setOnClickListener(new OnClickListener()
{
@override
public void onClick(View arg0)
{
File file_cust_id=new File(file_Path + "customer.properties");
if(file_cust_id.exists())
{
Intent i = new Intent(Welcome.this, Login.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
finish();
}
else
{
Toast.makeText(getApplicationContext(),"Please Register First",Toast.LENGTH_LONG).show();
}
}
});
//Locate us button
Locate_us.setOnClickListener(new OnClickListener()
{
@override
public void onClick(View v)
{
try
{
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("https://www.google.co.in/maps/place...!1s0x3be7d1e96fffffff:0x5e96526f98c8e98?hl=en "));
startActivity(intent);
// Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
// intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// startActivity(intent);
// // finish();
}
catch(Exception ex)
{
Toast.makeText(getApplicationContext(),"Error In Google Maps",Toast.LENGTH_LONG).show();
}
}
});
}
//Copy Property Files from Asset Folder to SD card on startup
public void copyFiles()
{
try
{
File dataDirectory = new File(file_Path);
// have the object build the directory structure, if needed.
if(!dataDirectory.exists())
dataDirectory.mkdirs();
AssetManager am = getAssets();
String[] list = am.list("");
for (String s:list)
{
if (s.startsWith("config"))
{
InputStream inStream = am.open(s);
int size = inStream.available();
byte[] buffer = new byte[size];
inStream.read(buffer);
inStream.close();
FileOutputStream fos = new FileOutputStream(file_Path + s);
fos.write(buffer);
fos.close();
}
}
}
catch (Exception ex)
{
tc.WriteToTransactionLog("Exception: Welcome.java copyFiles():- "+ex.toString());
ex.printStackTrace();
}
}
@override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ( keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)
{
onBackPressed();
}
return super.onKeyDown(keyCode, event);
}
@override
public void onBackPressed()
{
try
{
//Success Register dialog box
Exit e = new Exit(Welcome.this);
e.show();
e.setCanceledOnTouchOutside(false);
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void onDestroy()
{
super.onDestroy();
finish();
}
// public void onRestart()
// {
// super.onRestart();
// startActivity(new Intent(this, Welcome.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
// }
}
My Welcome.xml :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android "
xmlns:tools="http://schemas.android.com/tools "
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="forbes.welcome.Hdfc_welcome"
android:background="@drawable/bbk_base_screen">
- <ImageButton
android:id="@+id/image_user_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/image_register"
android:src="@drawable/user_login" />
<ImageButton
android:id="@+id/image_register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/register" />
<ImageButton
android:id="@+id/image_locateus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/image_register"
android:layout_alignParentRight="true"
android:src="@drawable/locate_us_icon" />
<!-- <TextView
android:id="@+id/text_hdfc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/text_welcome"
android:layout_below="@+id/text_welcome"
android:layout_marginLeft="20dp"
android:textColor="#d4ccb9"
android:textSize="24sp"
android:textStyle="bold|italic"
android:text="M-Passbook" /> -->
<!-- <EditText
android:id="@+id/editText_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#d4ccb9"
android:drawableLeft="@drawable/user_icon"
android:layout_centerHorizontal="true"
android:layout_below="@+id/text_hdfc"
android:ems="10"
android:maxLength="15"
android:layout_marginTop="20dp"
android:hint="@String /user_name" >
</EditText>
<EditText
android:id="@+id/editText_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#d4ccb9"
android:drawableLeft="@drawable/key_icon"
android:ems="10"
android:maxLength="15"
android:hint="@String /password"
android:layout_centerHorizontal="true"
android:layout_below="@+id/editText_user"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:inputType="textPassword" />
<ImageButton
android:id="@+id/button_login"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignTop="@+id/editText_user"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_toRightOf="@+id/editText_password"
android:src="@drawable/unlock_icon" /> -->
<TextView
android:id="@+id/text_welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/image_user_login"
android:layout_centerHorizontal="true"
android:layout_marginTop="28dp"
android:text="Welcome To mPassbook"
android:textColor="#d4ccb9"
android:textSize="24sp"
android:textStyle="italic" />
</RelativeLayout>
...eschew obfuscation...
Administrator
Moved to Application Development forum for better exposure.