hosseinrasouli
پنج شنبه 20 شهریور 1393, 23:07 عصر
سلام به دوستان .
برنامه را هم با متد Finish() و هم با تابع زیر امتحان کردم . جالبی اینکه برنامه بسته میشه ولی دوباره راه اندازی میشه.
با این کد هم بررسی کردم:
protected void onDestroy() {
android.os.Process.killProcess(android.os.Process. myPid());
super.onDestroy();
}
کد کامل : دوستان راهنمایی کنند ( هر چی کردم نشد کلافم کرد)
package com.hrasouli.chardahmahsoom;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Application;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Typeface;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn_fehrest=(Button) findViewById(R.id.button1);
Button btn_temas=(Button) findViewById(R.id.button2);
Button btn_about=(Button) findViewById(R.id.button3);
Button btn_exit=(Button) findViewById(R.id.button4 );
Typeface bkoodak=Typeface.createFromAsset(getAssets(), "font/BKoodkBd.ttf");
btn_fehrest.setTypeface(bkoodak);
btn_temas.setTypeface(bkoodak);
btn_about.setTypeface(bkoodak);
btn_exit.setTypeface(bkoodak);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENT ATION_PORTRAIT);
btn_fehrest.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent page=new Intent(MainActivity.this,Activity2.class);
startActivity(page);
}
});
btn_temas.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent page=new Intent(MainActivity.this,Temas.class);
startActivity(page);
}
});
btn_about.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent page=new Intent(MainActivity.this,About.class);
startActivity(page);
}
});
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
btn_exit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
alert();
}
});
}
//////////////////////////////////////////////////////////////////////////////////////////
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_share:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
String str="دانلود نرم افزار : \n لينک دانلود : www.google.com";
shareIntent.putExtra(Intent.EXTRA_TEXT,str);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, R.string.zendegi_chardah_mahsoom);
startActivity(Intent.createChooser(shareIntent, "اشتراک گذاري ..."));
return true;
case R.id.action_setting:
Intent page_setting=new Intent(MainActivity.this,Setting.class);
startActivity(page_setting);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
//////////////////////////////////////////////////////////////////////////////////////////
public void onBackPressed() {
alert();
}
///////////////////////////////////////////////////////////////////////////////////////////
private void alert() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
alertDialog.setTitle(R.string.tmessage);
alertDialog.setMessage(R.string.message);
alertDialog.setIcon(R.drawable.ic_action_help);
// Setting Positive "Yes" Button
alertDialog.setPositiveButton(R.string.yes,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
onDestroy();
finish();
}
});
// Setting Negative "NO" Button
alertDialog.setNegativeButton(R.string.no,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
// Showing Alert Message
alertDialog.show();
}
////////////////////////////////////////////////////////////////////////////////////////
protected void onDestroy() {
android.os.Process.killProcess(android.os.Process. myPid());
super.onDestroy();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
برنامه را هم با متد Finish() و هم با تابع زیر امتحان کردم . جالبی اینکه برنامه بسته میشه ولی دوباره راه اندازی میشه.
با این کد هم بررسی کردم:
protected void onDestroy() {
android.os.Process.killProcess(android.os.Process. myPid());
super.onDestroy();
}
کد کامل : دوستان راهنمایی کنند ( هر چی کردم نشد کلافم کرد)
package com.hrasouli.chardahmahsoom;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Application;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Typeface;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn_fehrest=(Button) findViewById(R.id.button1);
Button btn_temas=(Button) findViewById(R.id.button2);
Button btn_about=(Button) findViewById(R.id.button3);
Button btn_exit=(Button) findViewById(R.id.button4 );
Typeface bkoodak=Typeface.createFromAsset(getAssets(), "font/BKoodkBd.ttf");
btn_fehrest.setTypeface(bkoodak);
btn_temas.setTypeface(bkoodak);
btn_about.setTypeface(bkoodak);
btn_exit.setTypeface(bkoodak);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENT ATION_PORTRAIT);
btn_fehrest.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent page=new Intent(MainActivity.this,Activity2.class);
startActivity(page);
}
});
btn_temas.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent page=new Intent(MainActivity.this,Temas.class);
startActivity(page);
}
});
btn_about.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent page=new Intent(MainActivity.this,About.class);
startActivity(page);
}
});
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
btn_exit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
alert();
}
});
}
//////////////////////////////////////////////////////////////////////////////////////////
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_share:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
String str="دانلود نرم افزار : \n لينک دانلود : www.google.com";
shareIntent.putExtra(Intent.EXTRA_TEXT,str);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, R.string.zendegi_chardah_mahsoom);
startActivity(Intent.createChooser(shareIntent, "اشتراک گذاري ..."));
return true;
case R.id.action_setting:
Intent page_setting=new Intent(MainActivity.this,Setting.class);
startActivity(page_setting);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
//////////////////////////////////////////////////////////////////////////////////////////
public void onBackPressed() {
alert();
}
///////////////////////////////////////////////////////////////////////////////////////////
private void alert() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
alertDialog.setTitle(R.string.tmessage);
alertDialog.setMessage(R.string.message);
alertDialog.setIcon(R.drawable.ic_action_help);
// Setting Positive "Yes" Button
alertDialog.setPositiveButton(R.string.yes,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
onDestroy();
finish();
}
});
// Setting Negative "NO" Button
alertDialog.setNegativeButton(R.string.no,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
// Showing Alert Message
alertDialog.show();
}
////////////////////////////////////////////////////////////////////////////////////////
protected void onDestroy() {
android.os.Process.killProcess(android.os.Process. myPid());
super.onDestroy();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}