我无法从Build Apk选项运行Apk而不是,当我通过USB调试将apk部署到手机时,应用程序运行非常流畅和精细,应用程序中没有错误导致它强行关闭。问题出在HomeActivity上,这个活动只是在测试包含片段的App时才加载,下面给出了活动代码。
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import com.darkweb.android.amityaaroh.R;
public class Home extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(Home.this, "Use Gmail To Contact Us", Toast.LENGTH_SHORT).show();
sendEmail();
}
private void sendEmail() {
Log.i("Send email", "");
String[] TO = {""};
String[] CC = {""};
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL,new String[]{"priyansh.mishra19@gmail.com"});
emailIntent.putExtra(Intent.EXTRA_CC, CC);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Aaroh:Enquiry");
emailIntent.putExtra(Intent.EXTRA_TEXT, " ");
try {
startActivity(Intent.createChooser(emailIntent,"Send mail..."));
finish();
Log.i("Finished sending email...", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(Home.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
}
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
displaySelectedScreen(R.id.nav_homepage);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
displaySelectedScreen(item.getItemId());
return true;
}
private void displaySelectedScreen(int itemId) {
//creating fragment object
Fragment fragment = null;
//initializing the fragment object which is selected
switch (itemId) {
case R.id.nav_homepage:
fragment = new HomePage();
break;
case R.id.nav_coordinator:
fragment = new Coordinators();
break;
case R.id.nav_events:
fragment = new events();
break;
case R.id.nav_about:
fragment = new About();
break;
case R.id.nav_developer:
fragment = new Developer_info();
break;
case R.id.nav_contact:
fragment = new Contact();
break;
case R.id.nav_winner:
fragment = new Winners();
break;
case R.id.nav_timing:
fragment = new Event_time();
break;
case R.id.nav_userprofile:
fragment = new User_Profile();
break;
}
//replacing the fragment
if (fragment != null) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.content_frame, fragment);
ft.commit();
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
}
}
下面给出了未加载的片段Home_Page的代码
public class HomePage extends android.support.v4.app.Fragment {
TabLayout tabLayout;
ViewPager viewPager;
ViewPager mPager;
int images[] = {R.drawable.aump1, R.drawable.aump2 ,R.drawable.aump3, R.drawable.aump4};
MyCustomPagerAdapter myCustomPagerAdapter;
@Nullable
@Override
//@SuppressLint("ValidFragment")
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.activity_homepage, container, false);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getActivity().setTitle("Home Page");
viewPager = (ViewPager)view.findViewById(R.id.viewpager);
setupViewPager(viewPager);
tabLayout = (TabLayout)view.findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
mPager = (ViewPager)view.findViewById(R.id.viewPager);
myCustomPagerAdapter = new MyCustomPagerAdapter(HomePage.this.getActivity(), images);
mPager.setAdapter(myCustomPagerAdapter);
final Handler handler = new Handler();
handler.postDelayed( new Runnable() {
int item_count=0;
@Override
public void run() {
mPager.setCurrentItem(item_count);
if (item_count == 10) {
item_count=0;
} else {
item_count++;
}
handler.postDelayed(this, 3000);
}
} , 3000);
}
public void setupViewPager(ViewPager viewPager) {
ViewPagerAdapter adapter = new ViewPagerAdapter(getChildFragmentManager());
adapter.addFragment(new Main_Home(), "Home");
adapter.addFragment(new Activities(), "Cultural Events");
adapter.addFragment(new Competitions(), "Competition");
adapter.addFragment(new Sponsors(), "Sponsors");
viewPager.setAdapter(adapter);
}
public class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public ViewPagerAdapter(FragmentManager manager)
{
super(manager);
}
@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
@Override
public int getCount()
{
return mFragmentList.size();
}
public void addFragment(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
@Override
public CharSequence getPageTitle(int position)
{
return mFragmentTitleList.get(position);
}
}
}
Android监视器消息:
10-06 23:21:20.888 14028-14063/com.darkweb.android.amityaaroh V/FA: Inactivity, disconnecting from AppMeasurementService
10-06 23:21:23.649 14028-14028/com.darkweb.android.amityaaroh W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
10-06 23:21:25.706 14028-14063/com.darkweb.android.amityaaroh V/FA: Session started, time: 540154589
10-06 23:21:25.711 14028-14063/com.darkweb.android.amityaaroh I/FA: Tag Manager is not found and thus will not be used
10-06 23:21:25.712 14028-14063/com.darkweb.android.amityaaroh D/FA: Logging event (FE): _s, Bundle[{_o=auto}]
10-06 23:21:25.713 14028-14063/com.darkweb.android.amityaaroh V/FA: Using measurement service
10-06 23:21:25.713 14028-14063/com.darkweb.android.amityaaroh V/FA: Connecting to remote service
10-06 23:21:25.721 14028-14063/com.darkweb.android.amityaaroh D/FA: Connected to remote service
10-06 23:21:25.721 14028-14063/com.darkweb.android.amityaaroh V/FA: Processing queued up service tasks: 1
10-06 23:21:25.730 29459-14142/? V/FA-SVC: Logging event: origin=auto,name=session_start(_s),params=Bundle[{firebase_event_origin(_o)=auto}]
10-06 23:21:25.738 29459-14142/? V/FA-SVC: Saving event, name, data size: session_start(_s), 14
10-06 23:21:25.739 29459-14142/? V/FA-SVC: Event recorded: Event{appId='com.darkweb.android.amityaaroh', name='session_start(_s)', params=Bundle[{firebase_event_origin(_o)=auto}]}
10-06 23:21:25.745 29459-14142/? V/FA-SVC: Upload scheduled in approximately ms: 216
10-06 23:21:25.777 29459-14142/? V/FA-SVC: Cancelling job. JobID: 812057698
10-06 23:21:25.780 29459-14142/? V/FA-SVC: Scheduling upload with DelayedRunnable
10-06 23:21:25.780 29459-14142/? V/FA-SVC: Scheduling upload with AlarmManager
10-06 23:21:25.822 29459-14142/? V/FA-SVC: Background event processing time, ms: 93
10-06 23:21:25.997 29459-14142/? V/FA-SVC: Sending upload intent from DelayedRunnable
10-06 23:21:26.004 29459-29459/? V/FA-SVC: Device receiver got: com.google.android.gms.measurement.UPLOAD
10-06 23:21:26.017 29459-29459/? V/FA-SVC: Device PackageMeasurementService is starting up
10-06 23:21:26.017 29459-29459/? V/FA-SVC: Device PackageMeasurementService called. startId, action: 1, com.google.android.gms.measurement.UPLOAD
10-06 23:21:26.019 29459-14142/? D/FA-SVC: Uploading events. Elapsed time since last upload attempt (ms): 10057
10-06 23:21:26.022 29459-14142/? V/FA-SVC: Fetching remote configuration: com.darkweb.android.amityaaroh
10-06 23:21:26.023 29459-14142/? V/FA-SVC: Not stopping services. fetch, network, upload: true, false, false
10-06 23:21:26.218 29459-14142/? V/FA-SVC: onConfigFetched. Response size: 0
10-06 23:21:26.222 29459-14142/? V/FA-SVC: Successfully fetched config. Got network response. code, size: 304, 0
10-06 23:21:26.265 29459-14142/? V/FA-SVC: Saving bundle, size: 404
10-06 23:21:26.266 29459-14142/? D/FA-SVC: Uploading events. Elapsed time since last upload attempt (ms): 10272
10-06 23:21:26.269 29459-14142/? V/FA-SVC: Uploading data. app, uncompressed size, data: com.darkweb.android.amityaaroh, 494,
batch {
bundle {
protocol_version: 1
platform: android
gmp_version: 9452
uploading_gmp_version: 11517
config_version: 1506927976668530
gmp_app_id: 1:18560328138:android:a0727ccc4b032b68
app_id: com.darkweb.android.amityaaroh
app_version: 1.0
app_version_major: 1
firebase_instance_id: eppKbsaWKHU
dev_cert_hash: -1076636081997616382
app_store: com.google.android.packageinstaller
upload_timestamp_millis: 1507312286233
start_timestamp_millis: 1507312275893
end_timestamp_millis: 1507312285707
app_instance_id: 061ef57a7bc88835a2cb2c3761e50960
resettable_device_id: 8bf60814-8360-4cd7-8abc-fee8d9e1ae5f
limited_ad_tracking: false
os_version: 7.0
device_model: SM-G935F
user_default_language: en-us
time_zone_offset_minutes: 330
bundle_sequential_index: 1
service_upload: true
user_property {
set_timestamp_millis: 1507312275893
name: first_open_time(_fot)
int_value: 1507312800000
}
user_property {
set_timestamp_millis: 1507312275893
name: first_open_after_install(_fi)
int_value: 1
}
event {
name: first_open(_f)
timestamp_millis: 1507312275893
previous_timestamp_millis: 0
param {
name: firebase_conversion(_c)
int_value: 1
}
param {
name: firebase_event_origin(_o)
string_value: auto
}
param {
name: _r
int_value: 1
}
param {
name: previous_first_open_count(_pfo)
int_value: 12
}
param {
name: system_app(_sys)
int_value: 0
}
param {
name: update_with_analytics(_uwa)
int_value: 0
}
param {
name: system_app_update(_sysu)
int_value: 0
}
}
event {
name: user_engagement(_e)
timestamp_millis: 1507312275893
previous_timestamp_millis: 0
param {
name: firebase_event_origin(_o)
string_value: auto
}
param {
name: engagement_time_msec(_et)
int_value: 1
}
}
event {
name: session_start(_s)
timestamp_millis: 1507312285707
previous_timestamp_millis: 0
param {
name: firebase_event_origin(_o)
string_value: auto
}
}
}
}
10-06 23:21:26.269 29459-14142/? V/FA-SVC: Not stopping services. fetch, network, upload: true, true, false
10-06 23:21:26.275 29459-14142/? V/FA-SVC: Not stopping services. fetch, network, upload: false, true, false
10-06 23:21:26.276 29459-14976/? V/FA-SVC: Uploading data. size: 425
10-06 23:21:26.452 29459-14142/? V/FA-SVC: Upload scheduled in approximately ms: 3599997
10-06 23:21:26.457 29459-14142/? V/FA-SVC: Cancelling job. JobID: 812057698
10-06 23:21:26.457 29459-14142/? V/FA-SVC: Scheduling upload with AlarmManager
10-06 23:21:26.464 29459-14142/? V/FA-SVC: Successful upload. Got network response. code, size: 204, 0
10-06 23:21:26.474 29459-14142/? V/FA-SVC: Nothing to upload or uploading impossible
10-06 23:21:26.481 29459-14142/? V/FA-SVC: Cancelling job. JobID: 812057698
10-06 23:21:26.481 29459-14142/? V/FA-SVC: Stopping uploading service(s)
10-06 23:21:26.482 29459-14142/? V/FA-SVC: Device PackageMeasurementService processed last upload request. StartId: 1
10-06 23:21:26.482 29459-29459/? V/FA-SVC: Device PackageMeasurementService is shutting down
10-06 23:21:29.925 14028-14063/com.darkweb.android.amityaaroh V/FA: Activity paused, time: 540158808
10-06 23:21:29.959 14028-14028/com.darkweb.android.amityaaroh V/FA: onActivityCreated
10-06 23:21:30.072 14028-14063/com.darkweb.android.amityaaroh V/FA: Activity resumed, time: 540158955